You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, we now have a variable ``timeIndex`` in the Pandas datetime format with dates for January 1 of the past 4 years.
67
+
The starting and ending years are clear, and the ``freq='AS'`` indicates the frequecy of dates between the listed starting and ending times.
68
+
In this case, ``AS`` refers to annual values (1 time per year) at the start of the year.
69
+
70
+
With the ``timeIndex`` variable, we can now create our empty DataFrame to store the seasonal jacket numbers using the Pandas ``pd.DataFrame()`` function.
Now we have our empty DataFrame where I can fill in the number of times I needed a jacket in each season using the date index!
78
+
79
+
Slicing up the seasons
80
+
----------------------
81
+
82
+
The other main task in Problem 2 is to sort values from the different months into seasonal average values.
83
+
There are several ways in which this can be done, but one nice way to do it is using a ``for`` loop to loop over each year of data you consider and then fill in the seasonal values for that year.
84
+
For each year, you want to identify the slice of dates that correspond to that season, calculate their mean, then store that result in the corresponding location in the new DataFrame created in the previous hint.
85
+
For the ``for`` loop itself, it may be easiest to start with the second full year of data (1953), since we do not have temperatures for December of 1951.
86
+
If you loop over the years from 1953-2016, you can then easily calculate the seasonal average temperatures for each season.
87
+
For the winter, you can use ``year - 1`` to find the temperature for December, assuming ``year`` is your variable for the current year in your ``for`` loop.
88
+
89
+
In `this week's lesson <https://geo-python.github.io/2017/lessons/L7/pandas-plotting.html#selecting-data-based-on-time-in-pandas>`__ we saw how to select a range of dates, but we did not cover how to take the mean value of the slice and store it.
90
+
Because a slice of a DataFrame is still a DataFrame object, we can simply use the ``.mean()`` method to calculate the mean of that slice.
0 commit comments