EL-AJI Oussama
EL-AJI Oussama

Reputation: 426

Remove excel duplicated with ignoring case - Python pandas

I have a excel file with this data

Python
C++
Pandas
python
PHP

and I want to remove duplicated with ignoring case, my code :

import pandas as pd
data = pd.read_excel('data.xlsx', header=None)
data = data.drop_duplicates()
data.to_excel('sts.xlsx', index=False, header=False)

Upvotes: 1

Views: 65

Answers (1)

U13-Forward
U13-Forward

Reputation: 71600

Try this instead:

import pandas as pd
data = pd.read_excel('data.xlsx', header=None)
data = data.iloc[data.iloc[:, 0].str.lower().drop_duplicates().index]
data.to_excel('sts.xlsx', index=False, header=False)

Upvotes: 2

Related Questions