I have a pandas dataframe as follows.
df
Scenario Savings PC1 PC2
0 HI Total_FFC_base0 0.12 0.13
1 HI Total_FFC_savings1 0.15 0.12
2 HI Total_FFC_savings2 0.12 0.14
3 HI Total_FFC_savings3 0.17 0.15
4 HI Total_site_base0 0.12 0.15
5 HI Total_site_savings1 0.15 0.15
I want to replace df.Savings and created another column df['EL'] by extracting some of the string form column 'Savings, so the df looks like this:
df
Scenario Savings EL PC1 PC2
0 HI FFC 0 0.12 0.13
1 HI FFC 1 0.15 0.12
2 HI FFC 2 0.12 0.14
3 HI FFC 3 0.17 0.15
4 HI site 0 0.12 0.15
5 HI site 1 0.15 0.15
I used the following code to replace df['Savings].
df['Saving']=df['Savings'].str.split('_')[1]
However, I got the following error message.
"Can only use .str accessor with string values, which use np.object_ dtype in pandas"
Thank you for your help.