1

can I use dataframe.set_index with the index of the column or it only works with the name of the column??

Example:

df4 = df.set_index(0).T instead of df4 = df.set_index('Parametres').T

thank you

2

1 Answer 1

2

If want create new index by first column use indexing:

df = pd.DataFrame({
        'A':list('abcdef'),
         'B':[4,5,4,5,5,4],
         'C':[7,8,9,4,2,3],
})

print (df.columns[0])
A

df = df.set_index(df.columns[0])
print (df)
   B  C
A      
a  4  7
b  5  8
c  4  9
d  5  4
e  5  2
f  4  3
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.