Skip to content
Snippets Groups Projects
4b-exercise_pandas.ipynb 3.44 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Testing You in Pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given the Risø V52 met mast data, let's select and make some plots.\n",
    "\n",
    "### Exercises\n",
    "\n",
    "Make the following plots:  \n",
    "1. For a wind speed sector from 250 to 340 degrees, plot a histogram of the mean cup anemometer mean wind speed at 70 m.  \n",
    "2. Scatter plot the turbulence intensity versus the mean wind speed for two heights (your choice). Overlaid plots are preferred, but if you can't figure out how to do it, then separate plots are fine.\n",
    "\n",
    "Be sure to add axis labels, legends, titles, etc., where applicable."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Preliminaries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As always, we must first import the modules we want to use before we can write any code. I'm also setting the jupyter matploblib option to be interactive, as we can do in notebooks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "% matplotlib notebook\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Load the mean and std dev `.csv` files to dataframes and concatenate them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dfs = []\n",
    "for csv_name, suffix in zip(['demo_risoe_data_means.csv', 'demo_risoe_data_stdvs.csv'], ['_mean', '_stdv']):\n",
    "    df_path = f'data/{csv_name}'\n",
    "    df = pd.read_csv(df_path)  # load csv to dataframe\n",
    "    df['name'] = pd.to_datetime(df['name'].astype(str), format='%Y%m%d%H%M')  # convert name to datetime\n",
    "    df.set_index('name', inplace=True)  # set name as index\n",
    "    df = df.add_suffix(suffix)\n",
    "    dfs.append(df)\n",
    "met_df = pd.concat(dfs, axis=1);  # suppress jupyter output with semicolon"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 1: Wind Speed Histogram for Sector\n",
    "\n",
    "For a wind speed sector from 250 to 340 degrees, plot a histogram of the mean cup anemometer mean wind speed at 70 m."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "  # insert code here!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 2: TI vs U\n",
    "\n",
    "Scatter plot the turbulence intensity versus the mean wind speed for two heights (your choice)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "  # insert code here!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}