Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
df4 = df.set_index(0).T
df4 = df.set_index('Parametres').T
thank you
df.set_index(df.iloc[:,0])
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
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
df.set_index(df.iloc[:,0])?