I like all these 'inplace' methods, and tried to use this to filter particular rows from my time-series dataframe:
df.drop(df[(df['location'] == 'City17') | (df['location'] == 'City17 ') | (df['location'] == 'CITY17')].index, inplace=True)
But surprisingly it removed way more data and I was left with only one date left. The date was somewhere from the middle of my DateTime
interval; not the first, nor the last. I've found the solution with the assignment statement like this:
df = df[(df['location'] != 'City17') & (df['location'] != 'City17 ') & (df['location'] != 'CITY17')]
Now I now that assignments are shorter and work faster than inplace
methods, but I still wonder why the first .drop
worked like that.
Update
Thanks to hongsy's comment and the best answer from his link, I've solved the issue. The point was in the date column format. It was the object
, and after I've transformed it to the DateTime
, my .drop
method performed correctly.
I still have no clue why it evaluates so, but this is another proof that all Date
columns should be the DateTime
type.