forked from brandon-rhodes/pycon-pandas-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.txt
197 lines (163 loc) · 4.5 KB
/
todo.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
TODO
unstack lets you type anything!
Remove 'Clip from' entries?
Picture - show axis=0 and axis=1 and level=0 and level=1
More tricks from http://pandas-docs.github.io/pandas-docs-travis/visualization.html
plus plotting?
carrying join data in a set vs list and performance difference?
Star Wars actors: how many movies did they each go on to be in?
plt.bar(x, y, align='center')
plt.plot()
s.set_index(drop=False)
s.set_index(append=True)
s.reset_index(level=)
s.reset_index(drop=True)
.map()?
df.index.names
s.order() vs s.sort()
s.order(na_position=...)
multiindexes? time series?
df.groupby(['A','B']).sum()
df.swaplevel()
df.reorder_levels()
pd.date_range('1/1/2012', periods=100, freq='S')
pd.date_range('3/6/2012 00:00', periods=5, freq='D')
pd.period_range('1990Q1', '2000Q4', freq='Q-NOV')
ts.resample('5Min', how='sum')
s.reindex()
s.reindex_axis()
ts2.reindex(ts.index, method='ffill') and other values for 'method'
5. nan, filling, interpolating?
5. data conversion - to/from dates and strings and numbers
df.dtypes
df.astype()
df.get_dtype_counts()?
df.select_dtypes()?
df.mean()
df.mean(1)
s.mode()
df.sum()
df.std()
df.drop_duplicates()
df["grade"] = df["raw_grade"].astype("category")
df["grade"].cat.categories = ["very good", "good", "very bad"]
df["grade"] = df["grade"].cat.set_categories(["very bad", "bad",
"medium", "good", "very good"])
6. data cleanup: merging two book sales reports
Credits
http://pandas.pydata.org/pandas-docs/dev/10min.html#min
http://pandas.pydata.org/pandas-docs/dev/basics.html
An Index is an "ordered multiset"
Series()
s.shift(2)
s.searchsorted()?
s.dtype
s.where(cond) and s.where(cond, other)
s.mask()
date_range()
DataFrame() from dict
df.convert_objects(convert_numeric=True) or convert_dates='coerce'
df.values.dtype?
df.T
df.sort_index() and how every level of a column index must be named
df.where()
df[n:m]
df2[df2['E'].isin(['two','four'])]
df['F'] = s1 (with alignment by index values)
df2[df2 > 0] = -df2
df.at
df.iat
df.loc[dates[0]]?
df.loc[:,['A','B']]
df.loc[:,'D'] = np.array([5] * len(df))
df.loc['20130102':'20130102',['A','B']]
df.loc['20130102',['A','B']]
df.loc['20130102','A']
df.at['20130102','A']
df.at[dates[0],'A'] = 0
df.iloc[3]
df.iloc[3:5,0:2]
df.iloc[[1,2,4],[0,2]]
df.iloc[1:3,:]
df.iloc[:,1:3]
df.iloc[1,1]
df.iat[1,1]
df.iat[0,1] = 0
df.ix
df.xs()
df.xs(drop_level=False)
df.xs(('one', 'bar'), level=('second', 'first'), axis=1)
or df.loc[:,('bar','one')]
df.lookup()
df.get(, default=)
df.reindex()
df.sub()
df.apply()
df.duplicated()
pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
pd.DataFrame(np.random.randn(8, 2), index=index, columns=['A', 'B'])
stacked = df2.stack()
stacked.unstack()
stacked.unstack(1)
stacked.unstack(0)
pd.pivot_table(df, values='D', index=['A', 'B'], columns=['C'])
pd.Series(np.random.randn(len(rng)), rng)
ts.tz_localize('UTC')
ts_utc.tz_convert('US/Eastern')
pd.date_range('1/1/2012', periods=5, freq='M')
ts.to_period()
ps.to_timestamp()
ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
df.sort("grade")
df.groupby("grade").size()
ts.cumsum()
ts.plot()
df.to_csv('foo.csv')
pd.read_csv('foo.csv')
HDF5, Excel
"The truth value of an array is ambiguous."
pd.isnull()
pd.concat()
pd.merge(left, right, on='key')
df.equals()
df1.combine_first(df2)
df1.combine(df2, combiner)
df.cumprod()
df.quantile()
s.idxmin(), s.idxmax()
cut()
qcut()
df.apply(np.cumsum) and df.apply(Series.interpolate) to run on each series
df.apply(lambda x: x.idxmax()) for date each max value occurred
.apply() with extra args
df.apply(Series.interpolate)
df.apply(raw=)
df.applymap()
s.map(Series({'six' : 6., 'seven' : 7.})) and back the other way (!)
panel?
s and df can share an index - but truncates; no check on sensibility
panel.apply(lambda x: x*2, axis='items')
panel.apply(lambda x: x.dtype, axis='items')
panel.apply(lambda x: x.sum(), axis='major_axis')
.align()
df.align(df2, join='inner')
df.align(df2, join='inner', axis=0)
df.drop()
s.rename()
df.iterrows()
df.itertuples()
pd.set_option('display.multi_sparse', False)
and the meaning of the word "hierarchical"
If index is not ordered, do ranges work? efficiently?
Dict with tuples as keys vs index with hierarchy.
There is no integer NA, so flips to float the moment you need NA.
NA, NaN, isnull, notnull.
Ranges are inclusive!
.ix[] vs .reindex()
df.transform()
index rename, set_names, set_levels, and set_labels
index & index, index | index
http://pandas.pydata.org/pandas-docs/dev/advanced.html#data-alignment-and-using-reindex ?
df.shape
df.count()
s.count()