Home > Software design >  Pandas data frame index setting Key value error
Pandas data frame index setting Key value error

Time:07-18

I have a data frame as shown below.

enter image description here

I need to set the 'xvalues' column as the index of this data frame.Below is my code.

df_thd_StepVF_funct_T.set_index('xvalues',inplace=True)

But this is giving me an error as shown below.May I know where I went wrong.

KeyError: "None of ['xvalues'] are in the columns"

CodePudding user response:

new_header = df_thd_StepVF_funct_T.iloc[0]
df_thd_StepVF_funct_T = df_thd_StepVF_funct_T[1:]
df_thd_StepVF_funct_T.columns = new_header

Then try again on df_thd_StepVF_funct_T.

CodePudding user response:

['xvalues'] is already index.

to double check that you can do

df_thd_StepVF_funct_T.reset_index(inplace=True)
print(df_thd_StepVF_funct_T)

then again

df_thd_StepVF_funct_T.set_index('xvalues',inplace=True)

you set again that column as index.

  • Related