0

I have a data frame, where one of the column is days.to.play. Now I want to drop any rows, where it is more than 1000. The name of the data frame is basketball_football_2.

I tried couple of solutions such as:

basketball_football_2.loc[~(basketball_football_2['days.to.play'] > 1000)]

OR

basketball_football_2['day.to.play'] = basketball_football_2[basketball_football_2['day.to.play'] >= 1000]

OR

basketball_football_2.drop(basketball_football_2.loc[basketball_football_2['days.to.play']>=1000].index, inplace=True)

but it is dropping all the values and making the entire data frame empty.

molamk
  • 4,076
  • 1
  • 13
  • 22
Saurabh
  • 121
  • 12

1 Answers1

0

As already provided by @Marek Here's the link which should help you: Deleting DataFrame row in Pandas based on column value

Here's the code just for the easy reference purpose:

basketball_football_2 = basketball_football_2[basketball_football_2['days.to.play'].values < 1000]

Note: It's really a bad practice to use "." in your column names. Instead use something like "_".

Good Luck!

May the CODE be with you!

  • This is working fine @Me-So-Cool. I am new to ML, so please excuse silly questions. Going by the same logic, if I do something like: basketball_football_1 = basketball_football_1[basketball_football_1['days.to.play'].values > 500 & basketball_football_1['days.to.play'].values < 1000] to select values between 500 and 1000, why I am getting error "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()". – Saurabh Feb 25 '19 at 02:23