Changing Values Of Elements In Pandas Datastructure
I have imported .xls file with ene2 = pd.read_excel('Energy Indicators.xls', index=False) head looks like this print(ene2.head()) Country Energy Supply Energ
Solution 1:
Instead of:
value = 'Gigajoules'
do this:
ene2.loc[ene2['Energy Supply'] == value, 'Energy Supply'] = 'Gigajoules'
You have to set it to the relevant cell, by filtering for the correct rows and columns with .loc
. The other answer is the simpler method, but I wanted you to understand that you are not making the changes back to the dataframe with just value = blah.
Solution 2:
You can simply use Series.replace
:
ene2['Energy Supply'] = ene2['Energy Supply'].replace('Petajoules', 'Gigajoules')
Post a Comment for "Changing Values Of Elements In Pandas Datastructure"