-1

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"

Hari
  • 333
  • 6
  • 18
  • There is no column named `'xvalues'`. Should be pretty obvious from your screenshot or by doing `print(df.columns)` – It_is_Chris Jul 18 '22 at 13:56
  • I think the error is quite clear... `xvalues` is not a column. Can you show the output of `df_thd_StepVF_funct_T.columns`? – Tomerikoo Jul 18 '22 at 13:57
  • Does this answer your question? [Python Pandas Replacing Header with Top Row](https://stackoverflow.com/q/31328861/6045800) – Tomerikoo Jul 18 '22 at 14:02

1 Answers1

1
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.

Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30