I have multiple column data frame with columns ['Country', 'Energy Supply', 'Energy Supply per Capita', '% Renewable'].
In the energy supply column, I want to convert the unit of the column to Peta from Giga. But in the process
energy['Energy Supply']*= energy['Energy Supply']
, when the value is like "...." (missing value is denoted by this), is also getting multiplied or say duplicated. Also, the string value in the column is also getting multiplied. (For eg original: Peta, after operation: PetaPetaPetaPeta...).
To stop this from happening, I am running this:
energy = pd.read_excel("Energy Indicators.xls",skiprows = 16, skip_footer = 38)
energy.drop(['Unnamed: 0','Unnamed: 1'],axis = 1, inplace = True)
energy.columns = ['Country', 'Energy Supply', 'Energy Supply per Capita', '% Renewable']
for i in energy['Energy Supply']:
if (isinstance(energy[i],int) == True):
energy['Energy Supply'][i]=energy['Energy Supply'][i]*1000000
return (energy)
But I am not getting the result i.e. to change the value of integer type variables only, and nothing is changing.
Where I think the problem lies in, the first two rows will give thefalse condition, as first rows are "String" and based on that, the program is not modifying the values, whereas I want to individually check if the value is of integer type and if it is, Multiplies the number by 1,000,000.
Input:
Country Energy Supply Energy Supply per Capita % Renewable
0 NaN Petajoules Gigajoules %
1 Afghanistan 321 10 78.6693
2 Albania 102 35 100
3 Algeria 1959 51 0.55101
4 American Samoa ... ... 0.641026
Expected Output:
Country Energy Supply Energy Supply per Capita % Renewable
0 NaN Petajoules Gigajoules %
1 Afghanistan 3210000 10 78.6693
2 Albania 1020000 35 100
3 Algeria 19590000 51 0.55101
4 American Samoa ... ... 0.641026
Current Output:
Country Energy Supply Energy Supply per Capita % Renewable
0 NaN PetajoulesPeta. Gigajoules %
1 Afghanistan 3210000 10 78.6693
2 Albania 1020000 35 100
3 Algeria 19590000 51 0.55101
4 American Samoa ........ ... 0.641026