slice¶
filter performance¶
https://medium.com/@thomas-jewson/faster-pandas-what-is-the-most-performant-filtering-method-a5dbb8f694dc
df[df['col'].values == 'xxxxxx'] #fastest
df[df.get('col').values == 'x'] #similar
df.query('col > 1') #slowest
slicing¶
df.ix[[0, 2], 'A'] #obsolete
df.at[ridx, 'A']
df.iat[1,2] #get a single value
#loc to index
df.loc[df.index[[0, 2]], 'A']
#index to loc
df.iloc[[0, 2], df.columns.get_loc('A')]
df.iloc[[0, 2], df.columns.get_indexer(['A', 'B'])]
msk = [True, False, True]
df.loc[msk, df.columns[2:]]
#multiIndex slicing
idx = pd.IndexSlice
df.loc[idx[:, r_level1], idx[:, 'c_level1']]
select rows using list¶
chained assignments¶
The SettingWithCopyWarning was created to flag potentially confusing chained assignments. With chained assignment, it is generally difficult to predict whether a view or a copy is returned. When filtering DataFrames, it is possible slice/index a frame to return either a view, or a copy.
such as: