0

I have a problem, I want to exclude from a column and drop from my DF all my rows finishing by "99".

I tried to create a list : filteredvalues = [x for x in df['XX'] if x.endswith('99')]

I have in this list all the concerned rows but how to apply to my DF and drop those rows :

I tried a few things but nothing works :

Lately I tried this :

df = df[df['XX'] not in filteredvalues]

Any help on this?

1 Answers1

0

Use the .str attribute, with corresponding string methods, to select such items. Then use ~ to negate the result, and filter your dataframe with that:

df = df[~df['XX'].str.endswith('99')]
9769953
  • 10,344
  • 3
  • 26
  • 37