Please help me to understand how to change dataframes in dictionary.
Let's consider the simplest case and create two dataframes and construct the dict from them.
dates = pd.date_range('20130101',periods=6)
df1 =pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
df2 =pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
DICTOR={}
DICTOR['d1']=df1
DICTOR['d2']=df2
m=DICTOR
Now I want to exclude rows from DataFrames inside dict m, for example rows with where values in B columns are zero or negative.
I tried following code:
for name,df in m.items():
for index, row in df.iterrows():
if df.at[index,'B']<0:
df.drop(index,axis=0)
or:
for name,df in m.items():
df=df[df.B>0]
but it does not work.
I guess my problem is due to mutable/immutable objects, but i'm not sure.