Skip to content

Commit 60bab7b

Browse files
Update all notebook to pandas version 0.18.
1 parent a2e62da commit 60bab7b

File tree

1 file changed

+16
-76
lines changed

1 file changed

+16
-76
lines changed

climate_timeseries/climate_timeseries.ipynb

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"outputs": [],
9292
"source": [
9393
"# Change this cell to the demo location on YOUR machine\n",
94-
"%cd ~/Projects/SciPy2015_pandas_tutorial/demos/climate_timeseries/\n",
94+
"%cd ~/Projects/pandas_tutorial/climate_timeseries/\n",
9595
"%ls"
9696
]
9797
},
@@ -1714,7 +1714,7 @@
17141714
"source": [
17151715
"# Frequencies can be specified as strings: \"us\", \"ms\", \"S\", \"T\", \"H\", \"D\", \"B\", \"W\", \"M\", \"A\", \"3min\", \"2h20\", ...\n",
17161716
"# More aliases at http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases\n",
1717-
"full_globe_temp.resample(\"M\")"
1717+
"full_globe_temp.resample(\"M\").mean()"
17181718
]
17191719
},
17201720
{
@@ -1725,7 +1725,7 @@
17251725
},
17261726
"outputs": [],
17271727
"source": [
1728-
"full_globe_temp.resample(\"10A\", how=\"mean\")"
1728+
"full_globe_temp.resample(\"10A\").mean()"
17291729
]
17301730
},
17311731
{
@@ -1920,7 +1920,7 @@
19201920
},
19211921
"outputs": [],
19221922
"source": [
1923-
"local_sea_level_stations.sort(\"Date\")"
1923+
"local_sea_level_stations.sort_values(by=\"Date\")"
19241924
]
19251925
},
19261926
{
@@ -1938,7 +1938,7 @@
19381938
},
19391939
"outputs": [],
19401940
"source": [
1941-
"local_sea_level_stations.sort([\"Date\", \"Country\"], ascending=False)"
1941+
"local_sea_level_stations.sort_values(by=[\"Date\", \"Country\"], ascending=False)"
19421942
]
19431943
},
19441944
{
@@ -2186,7 +2186,9 @@
21862186
"outputs": [],
21872187
"source": [
21882188
"full_globe_temp.plot()\n",
2189-
"pd.rolling_mean(full_globe_temp, 10).plot(figsize=LARGE_FIGSIZE)"
2189+
"rolled_series = full_globe_temp.rolling(window=10, center=False)\n",
2190+
"print rolled_series\n",
2191+
"rolled_series.mean().plot(figsize=LARGE_FIGSIZE)"
21902192
]
21912193
},
21922194
{
@@ -2648,7 +2650,7 @@
26482650
},
26492651
"outputs": [],
26502652
"source": [
2651-
"european_stations.sort(\"Country\")"
2653+
"european_stations.sort_values(by=\"Country\")"
26522654
]
26532655
},
26542656
{
@@ -2817,7 +2819,7 @@
28172819
"cell_type": "markdown",
28182820
"metadata": {},
28192821
"source": [
2820-
"There are 2 objects constructors inside Pandas and inside `statsmodels`. There has been talks about merging the 2 into SM, but that hasn't happened yet. OLS in statsmodels allows more complex formulas:"
2822+
"The recommeded way to build ordinaty least square regressions is by using `statsmodels`."
28212823
]
28222824
},
28232825
{
@@ -2888,39 +2890,6 @@
28882890
"plt.legend(loc=\"upper left\")"
28892891
]
28902892
},
2891-
{
2892-
"cell_type": "markdown",
2893-
"metadata": {},
2894-
"source": [
2895-
"OLS in pandas requires to pass a `y` series and an `x` series to do a fit of the form `y ~ x`. But the formula can be more complex by providing a `DataFrame` for x and reproduce a formula of the form `y ~ x1 + x2`. \n",
2896-
"\n",
2897-
"Also, OLS in pandas allows to do rolling and expanding OLS:"
2898-
]
2899-
},
2900-
{
2901-
"cell_type": "code",
2902-
"execution_count": null,
2903-
"metadata": {
2904-
"collapsed": false
2905-
},
2906-
"outputs": [],
2907-
"source": [
2908-
"from pandas.stats.api import ols as pdols"
2909-
]
2910-
},
2911-
{
2912-
"cell_type": "code",
2913-
"execution_count": null,
2914-
"metadata": {
2915-
"collapsed": true
2916-
},
2917-
"outputs": [],
2918-
"source": [
2919-
"# Same fit as above:\n",
2920-
"pd_model = pdols(y=mean_sea_level[\"mean_global\"], x=mean_sea_level[[\"northern_hem\", \"southern_hem\"]])\n",
2921-
"pd_model"
2922-
]
2923-
},
29242893
{
29252894
"cell_type": "code",
29262895
"execution_count": null,
@@ -3140,7 +3109,7 @@
31403109
"source": [
31413110
"# Not constant reads apparently. Let's downscale the frequency of the sea levels \n",
31423111
"# to monthly, like the temperature reads we have:\n",
3143-
"monthly_mean_sea_level = mean_sea_level.resample(\"MS\").to_period()\n",
3112+
"monthly_mean_sea_level = mean_sea_level.resample(\"MS\").mean().to_period()\n",
31443113
"monthly_mean_sea_level"
31453114
]
31463115
},
@@ -3259,8 +3228,9 @@
32593228
},
32603229
"outputs": [],
32613230
"source": [
3262-
"model = sm.ols(\"southern_hem ~ global_temp\", data=aligned_monthly_data).fit()\n",
3263-
"model.rsquared"
3231+
"model = sm.ols(\"southern_hem ~ global_temp\", data=aligned_monthly_data)\n",
3232+
"params = model.fit()\n",
3233+
"params.rsquared"
32643234
]
32653235
},
32663236
{
@@ -3278,7 +3248,7 @@
32783248
},
32793249
"outputs": [],
32803250
"source": [
3281-
"aligned_yearly_data = aligned_monthly_data.resample(\"A\")\n",
3251+
"aligned_yearly_data = aligned_monthly_data.resample(\"A\").mean()\n",
32823252
"aligned_yearly_data.plot()"
32833253
]
32843254
},
@@ -3329,7 +3299,7 @@
33293299
"source": [
33303300
"import statsmodels as sm\n",
33313301
"# Let's remove seasonal variations by resampling annually\n",
3332-
"data = giss_temp_series.resample(\"A\").to_timestamp()\n",
3302+
"data = giss_temp_series.resample(\"A\").mean().to_timestamp()\n",
33333303
"ar_model = sm.tsa.ar_model.AR(data, freq='A')\n",
33343304
"ar_res = ar_model.fit(maxlag=60, disp=True)"
33353305
]
@@ -3370,36 +3340,6 @@
33703340
"source": [
33713341
"# Your code here"
33723342
]
3373-
},
3374-
{
3375-
"cell_type": "markdown",
3376-
"metadata": {},
3377-
"source": [
3378-
"## Want to practice more?"
3379-
]
3380-
},
3381-
{
3382-
"cell_type": "markdown",
3383-
"metadata": {},
3384-
"source": [
3385-
"**EXERCISE (computations):** Refer to `exercises/stock_returns/stock_returns.py`"
3386-
]
3387-
},
3388-
{
3389-
"cell_type": "markdown",
3390-
"metadata": {},
3391-
"source": [
3392-
"**EXERCISE (stats, groupby, timeseries):** Refer to `exercises/pandas_wind_statistics/pandas_wind_statistics.py`"
3393-
]
3394-
},
3395-
{
3396-
"cell_type": "code",
3397-
"execution_count": null,
3398-
"metadata": {
3399-
"collapsed": false
3400-
},
3401-
"outputs": [],
3402-
"source": []
34033343
}
34043344
],
34053345
"metadata": {

0 commit comments

Comments
 (0)