Reputation: 134
I have a pandas data frame which I made using an text file in Python. I was able to read the data and made the dataframe but after some processing, I am having many redundant values in my dataframe and I want to remove the repeated values. I tried using
df2 = df1.drop_duplicates(subset=['FROM', 'ATTENDANCE'], keep = 'last', inplace=False)
df2
but still, the repeated data is there and is not removed. I tried everything with drop_duplicates() and nothing of them worked for me.
Upvotes: 0
Views: 24
Reputation: 150805
From your colab, df1
is a copy of another df
, so you can't really change the values of it's columns. You should do:
df1 = df[['FROM', 'ATTENDANCE']].copy()
df1['FROM'] = df1['FROM'].str.strip()
df2 = df1.drop_duplicates(keep='last')
Output:
FROM ATTENDANCE
2 Usha Dubey PRESENT
9 Pranjal Srivastava PRESENT
11 Jagriti Gupta PRESENT
12 Samaksh X A PRESENT
13 Bhavya Malik PRESENT
Upvotes: 1