Steak
Steak

Reputation: 544

How to Change the Value of an element in a df Pandas Python

Code:

import pandas as pd
df = pd.read_csv('Overbuff_scraped_22-04-2019.csv',encoding='latin')
df.to_csv('Overbuff_scraped_22-04-2019.csv',encoding='utf-8')
df2 = df.drop(['Unnamed: 0'],axis=1)
df2.rename(columns={'Pick_rate':'PickRate','Win_rate':'WinRate','Tie_Rate':'TieRate','On_fire':'OnFire'},inplace=True)
df2.head()

I would like to change the name of df2['Hero']=='Lúcio' to 'Lucio'. I do not know how to do this.

I have tried:

df2.rename(df2['Hero']=='Lúcio', 'Lucio')

but this does not work. enter image description here

Upvotes: 0

Views: 145

Answers (1)

BENY
BENY

Reputation: 323236

That is not the name , it is value , so we do

df2.loc[df2['Hero']=='Lúcio','Hero'] = 'Lucio'

Upvotes: 1

Related Questions