Skip to content

Commit b878c20

Browse files
Merge pull request #23 from jonathanrocher/feature/update_pandas_0.18
Feature: update to pandas 0.18
2 parents a2e62da + f318a39 commit b878c20

File tree

2 files changed

+21
-82
lines changed

2 files changed

+21
-82
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Packages needed
4747
If you already have a working distribution, you will need to make sure that you
4848
install or update all needed packages. To be able to run the examples, demoes
4949
and exercises, you must have the following packages installed:
50-
- pandas 0.15+
51-
- numpy 1.9+
52-
- matplotlib 1.4+
53-
- pytables 3.1.1+
50+
- pandas 0.18+
51+
- numpy 1.10+
52+
- matplotlib 1.5+
53+
- pytables 3.1+
5454
- jupyter 1.0 or ipython 4.0+ (for running, experimenting and doing exercises)
5555
- nose (only to test your python installation)
5656

climate_timeseries/climate_timeseries.ipynb

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
"import numpy as np\n",
7777
"import matplotlib.pyplot as plt\n",
7878
"\n",
79-
"from pandas import set_option\n",
80-
"set_option(\"display.max_rows\", 16)\n",
79+
"pd.set_option(\"display.max_rows\", 16)\n",
8180
"\n",
8281
"LARGE_FIGSIZE = (12, 8)"
8382
]
@@ -91,7 +90,7 @@
9190
"outputs": [],
9291
"source": [
9392
"# Change this cell to the demo location on YOUR machine\n",
94-
"%cd ~/Projects/SciPy2015_pandas_tutorial/demos/climate_timeseries/\n",
93+
"%cd ~/Projects/pandas_tutorial/climate_timeseries/\n",
9594
"%ls"
9695
]
9796
},
@@ -1714,7 +1713,7 @@
17141713
"source": [
17151714
"# Frequencies can be specified as strings: \"us\", \"ms\", \"S\", \"T\", \"H\", \"D\", \"B\", \"W\", \"M\", \"A\", \"3min\", \"2h20\", ...\n",
17161715
"# More aliases at http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases\n",
1717-
"full_globe_temp.resample(\"M\")"
1716+
"full_globe_temp.resample(\"M\").mean()"
17181717
]
17191718
},
17201719
{
@@ -1725,7 +1724,7 @@
17251724
},
17261725
"outputs": [],
17271726
"source": [
1728-
"full_globe_temp.resample(\"10A\", how=\"mean\")"
1727+
"full_globe_temp.resample(\"10A\").mean()"
17291728
]
17301729
},
17311730
{
@@ -1920,7 +1919,7 @@
19201919
},
19211920
"outputs": [],
19221921
"source": [
1923-
"local_sea_level_stations.sort(\"Date\")"
1922+
"local_sea_level_stations.sort_values(by=\"Date\")"
19241923
]
19251924
},
19261925
{
@@ -1938,7 +1937,7 @@
19381937
},
19391938
"outputs": [],
19401939
"source": [
1941-
"local_sea_level_stations.sort([\"Date\", \"Country\"], ascending=False)"
1940+
"local_sea_level_stations.sort_values(by=[\"Date\", \"Country\"], ascending=False)"
19421941
]
19431942
},
19441943
{
@@ -2186,7 +2185,9 @@
21862185
"outputs": [],
21872186
"source": [
21882187
"full_globe_temp.plot()\n",
2189-
"pd.rolling_mean(full_globe_temp, 10).plot(figsize=LARGE_FIGSIZE)"
2188+
"rolled_series = full_globe_temp.rolling(window=10, center=False)\n",
2189+
"print rolled_series\n",
2190+
"rolled_series.mean().plot(figsize=LARGE_FIGSIZE)"
21902191
]
21912192
},
21922193
{
@@ -2648,7 +2649,7 @@
26482649
},
26492650
"outputs": [],
26502651
"source": [
2651-
"european_stations.sort(\"Country\")"
2652+
"european_stations.sort_values(by=\"Country\")"
26522653
]
26532654
},
26542655
{
@@ -2817,7 +2818,7 @@
28172818
"cell_type": "markdown",
28182819
"metadata": {},
28192820
"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:"
2821+
"The recommeded way to build ordinaty least square regressions is by using `statsmodels`."
28212822
]
28222823
},
28232824
{
@@ -2888,39 +2889,6 @@
28882889
"plt.legend(loc=\"upper left\")"
28892890
]
28902891
},
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-
},
29242892
{
29252893
"cell_type": "code",
29262894
"execution_count": null,
@@ -3140,7 +3108,7 @@
31403108
"source": [
31413109
"# Not constant reads apparently. Let's downscale the frequency of the sea levels \n",
31423110
"# to monthly, like the temperature reads we have:\n",
3143-
"monthly_mean_sea_level = mean_sea_level.resample(\"MS\").to_period()\n",
3111+
"monthly_mean_sea_level = mean_sea_level.resample(\"MS\").mean().to_period()\n",
31443112
"monthly_mean_sea_level"
31453113
]
31463114
},
@@ -3259,8 +3227,9 @@
32593227
},
32603228
"outputs": [],
32613229
"source": [
3262-
"model = sm.ols(\"southern_hem ~ global_temp\", data=aligned_monthly_data).fit()\n",
3263-
"model.rsquared"
3230+
"model = sm.ols(\"southern_hem ~ global_temp\", data=aligned_monthly_data)\n",
3231+
"params = model.fit()\n",
3232+
"params.rsquared"
32643233
]
32653234
},
32663235
{
@@ -3278,7 +3247,7 @@
32783247
},
32793248
"outputs": [],
32803249
"source": [
3281-
"aligned_yearly_data = aligned_monthly_data.resample(\"A\")\n",
3250+
"aligned_yearly_data = aligned_monthly_data.resample(\"A\").mean()\n",
32823251
"aligned_yearly_data.plot()"
32833252
]
32843253
},
@@ -3329,7 +3298,7 @@
33293298
"source": [
33303299
"import statsmodels as sm\n",
33313300
"# Let's remove seasonal variations by resampling annually\n",
3332-
"data = giss_temp_series.resample(\"A\").to_timestamp()\n",
3301+
"data = giss_temp_series.resample(\"A\").mean().to_timestamp()\n",
33333302
"ar_model = sm.tsa.ar_model.AR(data, freq='A')\n",
33343303
"ar_res = ar_model.fit(maxlag=60, disp=True)"
33353304
]
@@ -3370,36 +3339,6 @@
33703339
"source": [
33713340
"# Your code here"
33723341
]
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": []
34033342
}
34043343
],
34053344
"metadata": {

0 commit comments

Comments
 (0)