Home > other >  The understanding of the Python dataframe delete data
The understanding of the Python dataframe delete data

Time:09-21

Df [' Elevator]=df loc [(df [' Elevator]=='have elevators') | (df [' Elevator]==' no Elevator), 'Elevator]

Above is the purpose of this code, in order to get rid of some random into the Elevator value value, leaving only 'have' and 'no Elevator Elevator, such value null,

But my personal understanding, this is the code above should be selected only Elevator value of with and without Elevator, the Elevator but in fact, this code also filter out the Elevator numerical null line,
Want to ask, why, what is the default definitions such as?

CodePudding user response:

You, in my opinion, the df [' Elevator] is based on the original df plus a column, the add a list of the number of rows and is the same as before, your filter to remove a certain lines, there is no line will use NaN to complement,
You can try data=https://bbs.csdn.net/topics/df.loc [(df [' Elevator]=='have elevators') | (df [' Elevator]==' no Elevator), 'Elevator]
Print (data)
Look at the results of the screening

CodePudding user response:

Or use df1=df [(df [' Elevator]=='have elevators') | (df [' Elevator]==' no Elevator)]

CodePudding user response:

The usage of the ground floor is what you want, the more formal way
  • Related