In [ ]:
%run setup_env.py
%matplotlib inline
In [ ]:
df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'])
df_mask = pd.DataFrame({
'A': [True] * 10,
'B': [False] * 10,
'C': [True, False] * 5
})
df.where(df_mask, -1000)
In [ ]:
df['logic'] = np.where(df['A'] > 0, 'ok', 'not ok')
df
In [ ]:
import functools
crit = functools.reduce(lambda x, y: x & y, [df['A'] > 0, df['B'] > 0, df['C'] < 0])
df[crit]
df[(df['A'] > 1) & (df.index.isin(range(5)))]
In [25]:
rng = pd.date_range('2014/1/1', periods=100, freq='D')
data = np.random.randn(100, 4)
cols = ['A', 'B', 'C', 'D']
df1 = df2 = df3 = pd.DataFrame(data, index=rng, columns=cols)
pf = pd.Panel({'df1': df1, 'df2': df2, 'df3': df3})
pft = pf.transpose(2, 0, 1)
pft
Out[25]: