Reputation: 321
I want to drop every dataframe that fullfils the condition in the if clause:
for i in range(0,len(df)):
if((df.iloc[i][5]=='District Steam') & (df.iloc[i][1]!='Baltimore')):
df.drop(df.iloc[i])
Whenever the 5. value is District Steam, I only want to keep the rows in which the city is Baltimore It provides the following error:
KeyError: "['Office' 'Miami' 'District Steam'] not found in axis"
Upvotes: 0
Views: 48
Reputation: 30930
I think you want:
df = df.loc[df.iloc[:, 5].ne('District Steam') | df.iloc[:, 1].eq('Baltimore')]
In other case please show an example and your expected output
Upvotes: 1