-1
print (amazon.shape)
print (amazon.drop(amazon[(amazon["Id"] > 150492) & (amazon["Id"] < 150530 )].index).shape)
print (amazon.shape)

output :

(525814, 10)
(525782, 10)
(525814, 10)

why is it not deleting 32 rows from main dataframe .?

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
Vishal Suryavanshi
  • 355
  • 1
  • 4
  • 15

2 Answers2

1

See drop's docs (emphasis mine):

DataFrame.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')

inplace : bool, default False

If True, do operation inplace and return None.

drop is not inplace by default. You have to explictly tell it to be:

amazon.drop(amazon[(amazon["Id"] > 150492) & (amazon["Id"] < 150530 )].index, inplace=True)

Or reassign it back to amazon (or to anything else):

amazon = amazon.drop(amazon[(amazon["Id"] > 150492) & (amazon["Id"] < 150530 )].index)
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
1

You need to do add the argument inplace=True otherwise it just returns a copy of the data frame with the row dropped.

Pallie
  • 965
  • 5
  • 10