Home > Blockchain >  How to filter the pandas dataframe using the 'not equal to' function?
How to filter the pandas dataframe using the 'not equal to' function?

Time:10-19

I'm trying the filter a pandas dataframe by using != operator. I want to filter the table by removing 'Falcon 1' from the 'BoosterVersion' row and I have been using this to run the code,

data_falcon9 = df[df['BoosterVersion'] != 'Falcon 1']

But everytime I ran into an error, KeyError: 'BoosterVersion'

Could someone please help me with this?

Thanks, Dave enter image description here

CodePudding user response:

BoosterVersion not a column. try:

data_falcon9 = df.T  #transpose
data_falcon9 = data_falcon9 [data_falcon9 ['BoosterVersion'] != 'Falcon 1']

CodePudding user response:

data_falcon9 = df.T #or df.transpose() 

this will transpose your dataframe and make BoosterVersion a columns that's why it was giving you key error.

#now you can filter it
data_falcon9 = data_falcon9 [data_falcon9 ['BoosterVersion'] != 'Falcon 1']

#if you want the original dataframe transpose again
df_without_falcon1 = data_falcon9.T #or data_falcon9.transpose()
  • Related