I have 2 equal columns in a pandas data frame. Each of the columns have the same duplicates.
A B
1 1
1 1
2 2
3 3
3 3
4 4
4 4
I want to delete the duplicates only from column B so that the goal is like the following:
A B
1 1
1 2
2 3
3 4
3
4
4
I cloned the column B in a new DataFrame and used drop duplicates. The new dataframe with only the column B after drop_duplicates() looks like:
B
1
2
3
4
But when i took it back to the original data frame it looks like this:
A B
1 1
1
2 2
3 3
3
4 4
4
My Code:
df[['A','B']]
df1=df['B']
df1=df1.sort_values()
df1.drop_duplicates(keep='first', inplace=True)
df1.to_numpy()
df['B']=df1