Import module

#import modules
import pandas as pd
 

Create a dummy dataframe

#create a dataframe
data = {'name': ['Cristiano Ronaldo', 'Neymar','Kylian Mbappé','Erling Haaland','Léo Messi','Karim Benzema'],
'age': [36, 29,22,20,33,33],
'height_cm': [187, 175,178,194,170, 187],
'club': ['Juventus FC', 'Paris Saint Germain','Paris Saint Germain','Borussia Dortmund','FC Barcelona', 'Real Madrid'],
'country': ['Portugal', 'Brazil','France','Norway','Argentina','France']}
df = pd.DataFrame(data)
df
 
 nameageheight_cmclubcountry
0Cristiano Ronaldo36187Juventus FCPortugal
1Neymar29175Paris Saint GermainBrazil
2Kylian Mbappé22178Paris Saint GermainFrance
3Erling Haaland20194Borussia DortmundNorway
4Léo Messi33170FC BarcelonaArgentina
5Karim Benzema33187Real MadridFrance

 

Rename columns

#rename columns name and age
df.rename(columns={'name': 'full_name', 'age': 'player_age'}, inplace=True)
df
 
 full_nameplayer_ageheight_cmclubcountry
0Cristiano Ronaldo36187Juventus FCPortugal
1Neymar29175Paris Saint GermainBrazil
2Kylian Mbappé22178Paris Saint GermainFrance
3Erling Haaland20194Borussia DortmundNorway
4Léo Messi33170FC BarcelonaArgentina
5Karim Benzema33187Real MadridFrance

 

#drop duplicate rows
df = df.drop_duplicates(subset='name', keep='first')
df
 
 nameageheight_cmclubcountry
0Cristiano Ronaldo36187Juventus FCPortugal
2Neymar29175Paris Saint GermainBrazil
3Kylian Mbappé22178Paris Saint GermainFrance
4Erling Haaland20194Borussia DortmundNorway
5Léo Messi33170FC BarcelonaArgentina
7Karim Benzema33187Real MadridFrance
Looking for a job?
Join 5,000+ subscribers
No commitment. Cancel anytime.