Issue
I have a CSV that I'm cleaning up with the help of Python/Pandas however there is some duplicates that I want to clean up where everthing i have tried fails to drop the row,
So Target Colum is "Title", i want to remove entire row if string inside column contains the partial string 'NQR', I've tried:
df[~df['Title'].isin(['NQR', na=False])]
df[~df.Title.str.contains("NQR", na=False)]
discard = ["NQR"]
df[~df.Title.str.contains('|'.join(discard), na=False)]
none of these work, entire script runs with no errors and rows containing these are still there!
Solution
you can also use the str.contains() built-in case
parameter if you don't want to preform a case sensitive search.
df = df[~df['Title'].str.contains('NQR', na=False, case=False)].reset_index(drop=True)
Answered By - amance
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.