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 .?
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 .?
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)
You need to do add the argument inplace=True otherwise it just returns a copy of the data frame with the row dropped.