0

So, this is probably a really simple problem, but I've not found a solution yet. I apologize for my stupidity. (I'm guessing my ignorance of terminology has impeded my searching here)

I have a dictionary of dataframes (showing 2 in here, but it contains more).

    df_dict={'P1': df0,'P2': df1}

Each dataframe may or may not have rows that I need to remove for further processing. I can easily remove these rows from one dataframe like so:

    df0=df_dict['P1']
    df0=df0[df0.well !='1']

But if I loop through the dictionary like this, nothing happens. The unwanted rows are still in the dataframes.

    for key,df in df_dict.items():
        df=df[df.well !='1']

I stupidly plunked inplace=True into the .loc and obviously that didn't work. Side note, I can't do df[~df.well.str.contains('1')] because this would remove rows that have correct positions like 'A01'

Again, I'm probably doing something very ignorant, and am very grateful for your help!

  • Could you please add the sample dataframes and required outputs, so that error can be reproduced – Ashwin Geet D'Sa May 07 '20 at 10:42
  • 1
    Sorry Ashwin, I decided to work on something else for a while. When I came back to this Vijay (below) had given me a perfect fix! Thank you though! – forevernoob May 07 '20 at 14:42

1 Answers1

2

Please change the 'for loop' to as mentioned below :

for key,df in df_dict.items():
    df_dict[key]=df[df.well !='1']

This should fix the issue.

vbhargav875
  • 837
  • 8
  • 15