« Pandas
Convert the cases of the font.
upper():Lower case to Upper case
import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex']}
df = pd.DataFrame(data=my_dict)
print(df.NAME.str.upper())
Output
0 RAVI
1 RAJU
2 ALEX
lower() : Upper case to Lower case
import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex']}
df = pd.DataFrame(data=my_dict)
print(df.NAME.str.lower())
Output
0 ravi
1 raju
2 alex
title(): First char of each word to Upper case
import pandas as pd
my_dict={'NAME':['ravi ron','raju geek','alex john']}
df = pd.DataFrame(data=my_dict)
print(df.NAME.str.title())
Output
0 Ravi Ron
1 Raju Geek
2 Alex John
capitalize(): First Char to Upper case
import pandas as pd
my_dict={'NAME':['ravi ron','raju geek','alex john']}
df = pd.DataFrame(data=my_dict)
print(df.NAME.str.capitalize())
Output
0 Ravi ron
1 Raju geek
2 Alex john
swapcase(): Convert Lower to Uppper and Upper to Lower case
import pandas as pd
my_dict={'NAME':['Ravi Ron','Raju Geek','Alex John']}
df = pd.DataFrame(data=my_dict)
print(df.NAME.str.swapcase())
Output
0 rAVI rON
1 rAJU gEEK
2 aLEX jOHN
« Pandas
contains() split() slice()
← Subscribe to our YouTube Channel here