0

How to select a column with spaces in pandas dataframe and do logical operation. Below is the Code,

not_poodle = mpr[['Dog Breed'] != 'Poodle']

In the above code I am trying to select a column name with "Dog Breed' and doing the not equal comparison with Poodle. But it is throwing error

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    Use `not_poodle = mpr[mpr['Dog Breed'] != 'Poodle']` – jezrael Jan 06 '20 at 05:39
  • 1
    `df[column_name]` for selection. You cannot separate a df from it's column name when trying to select a column. `mpr[mpr['Dog Breed'] != 'Poodle']` where `mpr['Dog Breed']` is selecting the column, the condition is giving a boolean series, and finally `mpr[some_series_of_bools]` is acting as indexing. – Paritosh Singh Jan 06 '20 at 05:39

0 Answers0