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

newbie
  • 646
  • 8
  • 27

1 Answers1

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
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252