|
1 | 1 | .. _cookbook: |
2 | 2 |
|
3 | | -.. currentmodule:: pandas |
4 | | - |
5 | | -.. ipython:: python |
6 | | - :suppress: |
7 | | -
|
8 | | - import datetime |
9 | | - import functools |
10 | | - import glob |
11 | | - import itertools |
12 | | - import os |
13 | | -
|
14 | | - import numpy as np |
15 | | - import pandas as pd |
16 | | - from pandas.compat import StringIO |
17 | | -
|
18 | | -
|
19 | | - np.random.seed(123456) |
20 | | - np.set_printoptions(precision=4, suppress=True) |
21 | | - pd.options.display.max_rows = 15 |
22 | | -
|
| 3 | +{{ header }} |
23 | 4 |
|
24 | 5 | ******** |
25 | 6 | Cookbook |
@@ -186,6 +167,8 @@ One could hard code: |
186 | 167 |
|
187 | 168 | .. ipython:: python |
188 | 169 |
|
| 170 | + import functools |
| 171 | +
|
189 | 172 | CritList = [Crit1, Crit2, Crit3] |
190 | 173 | AllCrit = functools.reduce(lambda x, y: x & y, CritList) |
191 | 174 |
|
@@ -409,6 +392,8 @@ To take the cross section of the 1st level and 1st axis the index: |
409 | 392 |
|
410 | 393 | .. ipython:: python |
411 | 394 |
|
| 395 | + import itertools |
| 396 | +
|
412 | 397 | index = list(itertools.product(['Ada', 'Quinn', 'Violet'], |
413 | 398 | ['Comp', 'Math', 'Sci'])) |
414 | 399 | headr = list(itertools.product(['Exams', 'Labs'], ['I', 'II'])) |
@@ -1022,6 +1007,9 @@ You can use the same approach to read all files matching a pattern. Here is an |
1022 | 1007 |
|
1023 | 1008 | .. ipython:: python |
1024 | 1009 |
|
| 1010 | + import glob |
| 1011 | + import os |
| 1012 | +
|
1025 | 1013 | files = glob.glob('file_*.csv') |
1026 | 1014 | result = pd.concat([pd.read_csv(f) for f in files], ignore_index=True) |
1027 | 1015 |
|
@@ -1081,6 +1069,8 @@ Option 1: pass rows explicitly to skip rows |
1081 | 1069 |
|
1082 | 1070 | .. ipython:: python |
1083 | 1071 |
|
| 1072 | + from pandas.compat import StringIO |
| 1073 | +
|
1084 | 1074 | pd.read_csv(StringIO(data), sep=';', skiprows=[11, 12], |
1085 | 1075 | index_col=0, parse_dates=True, header=10) |
1086 | 1076 |
|
@@ -1327,6 +1317,8 @@ The :ref:`Timedeltas <timedeltas.timedeltas>` docs. |
1327 | 1317 |
|
1328 | 1318 | .. ipython:: python |
1329 | 1319 |
|
| 1320 | + import datetime |
| 1321 | +
|
1330 | 1322 | s = pd.Series(pd.date_range('2012-1-1', periods=3, freq='D')) |
1331 | 1323 |
|
1332 | 1324 | s - s.max() |
|
0 commit comments