Skip to content

Commit fb575e6

Browse files
committed
adding assignment 8
1 parent 8fe7362 commit fb575e6

3 files changed

Lines changed: 3303 additions & 0 deletions

File tree

assignments/assignment8.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
### Assignment 8 - Time Series and Group Operations
2+
3+
Complete the tasks below. Please turn in a single Jupyter notebook named `8_first_last.ipynb` (substitute your first and last name). Please run Kernel > Restart & Run All on your notebook before turning in.
4+
5+
#### Precipitation in La Jolla
6+
7+
For this assignment, we will use a file containing daily precipitation data in La Jolla from February 2009 to February 2018, which were downloaded from [NOAA](https://www.ncdc.noaa.gov/cdo-web/datasets/GHCND/stations/GHCND:US1CASD0030/detail) using "standard" (imperial) units (inches for precipitation, feet for elevation). Download the file from [GitHub](https://github.com/cuttlefishh/python-for-data-analysis/blob/master/data/la_jolla_precip_daily.csv).
8+
9+
**1.** Set up the file.
10+
11+
* Import the csv file as a Pandas DataFrame with default header and index.
12+
* Change the 'DATE' column to a timestamps using `pd.datetime()`.
13+
* What was the maximum daily precipitation (in inches) during this time period and when was it?
14+
15+
**2.** Explore the dataset.
16+
17+
* We don't need the columns 'SNOW' and 'SNOW_ATTRIBUTES' because there was no recorded snow in the dataset. Delete those columns "in place".
18+
* Find out about the sampling stations. Notice that the column values are similar between rows except 'DATE' and 'PRCP'. Explore these other columns using three different commands (we haven't covered them yet, but they are easy to use and you can always google them):
19+
* Use the `value_counts()` method for each of these columns: 'STATION', 'NAME', 'LATITUDE', 'LONGITUDE', and 'ELEVATION'. There should only be one cateogory for each calculation because all the data come from the same station. To see what output looks like for a more diverse series, use the `value_counts()` method on 'PRCP' and 'PRCP_ATTRIBUTES'.
20+
* Make a DataFrame with just the columns 'STATION', 'NAME', 'LATITUDE', 'LONGITUDE', and 'ELEVATION' and use the method `drop_duplicates()` to see all the unique combinations of values in those five columns.
21+
* Create a groupby object using `groupby('STATION')`, then use the `count()` method on that groupby object to count the number of values for each station.
22+
23+
**3.** Plot precipitation versus time.
24+
25+
* Use the Matplotlib function `plot()` to plot 'PRCP' versus 'DATE' as a line.
26+
* Plot 'PRCP' versus 'DATE' each year separately as a different colored line, with a legend indicating the year. Hint: You will have to extract the year from the date somehow, for example with the `.year` attribute or a regular expression, optionally creating a new column for the year.
27+
* Go back and recolor the two plots above: pick two colors from ColorBrewer or xkcd and draw your subplots again.
28+
* Replot the plots in a subplot with the two sets of axes in a 1x2 formation.
29+
30+
**4.** Plot distributions of the precipitation data.
31+
32+
* Plot a histogram of precipitation values using the Matplotlib function `hist()` or `violinplot()`.
33+
* Plot a histogram with kernel density and rugplot with the Seaborn function `distplot()`. Play around with the settings to make a histogram that represents the data well.
34+
* Add columns to the DataFrame for month and year. Hint: You can do this with list comprehension and the datetime attributes `month` and `year`.
35+
* Make boxplots by month using the Seaborn function `boxplot()`:
36+
* by year: Which year was the rainiest?
37+
* by month: Which month was the rainiest?
38+
39+
**5.** Pivoting, stacking and unstacking.
40+
41+
* Use pivot_table to produce a new DataFrame, where rows=years and columns=months, containing the mean precipitation of each month.
42+
* Draw a heatmap of years x months where each square is a month colored by mean precipitation. Adjust the colormap to highlight months with heavy precipitation. Hint: Seaborn's `heatmap()` function makes this very easy.
43+
* Stack the monthly precipitation table using `stack()`. View the values for 2017. Which month had the most precipitation in 2017? Describe the distribution statistics for all months using `describe()`. How many months are included in this dataset? What was the median month (daily average) value in this time period?
44+
* Use `unstack()` to stack precipitation pivot table by month and then year. View the values for December. Which year had the wettest December?

0 commit comments

Comments
 (0)