-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"

3
  • There is no column named 'xvalues'. Should be pretty obvious from your screenshot or by doing print(df.columns) Commented Jul 18, 2022 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? Commented Jul 18, 2022 at 13:57
  • Does this answer your question? Python Pandas Replacing Header with Top Row Commented Jul 18, 2022 at 14:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.