I have a data frame with one column (col). I’m trying to remove duplicate records regardless of lowercase or Uppercase, for example
JavaScript
x
3
1
df = pd.DataFrame({'Col': ['Appliance Identification', 'Natural Language','Social networks',
2
'natural language', 'Personal robot', 'Social Networks', 'Natural language']})
3
output:
JavaScript
1
9
1
Col
2
0 Appliance Identification
3
1 Natural Language
4
2 Social networks
5
3 natural language
6
4 Personal robot
7
5 Social Networks
8
6 Natural language
9
Expected Output:
JavaScript
1
6
1
Col
2
0 Appliance Identification
3
1 Social networks
4
2 Personal robot
5
3 Natural language
6
How can this Dropping be done regardless of case-insensitively?
Advertisement
Answer
You could use:
JavaScript
1
2
1
df.groupby(df['Col'].str.lower(), as_index=False, sort=False).first()
2
output:
JavaScript
1
6
1
Col
2
0 Appliance Identification
3
1 Natural Language
4
2 Social networks
5
3 Personal robot
6