Pratik Dutta
Pratik Dutta

Reputation: 125

How to make column header and row header same in a pandas dataframe

I currently have a dataframe that looks like this:

       A       B       C
0   0.6875  0.1923  0.2300
1   0.3887  0.1923  0.5300
2   0.6061  0.2576  0.2474

I'm looking for a way to and make the first column the same as the header row, so the new dataframe would look like this:

       A       B       C
A   0.6875  0.1923  0.2300
B   0.3887  0.1923  0.5300
C   0.6061  0.2576  0.2474

Can anyone please help me regarding this?

Upvotes: 0

Views: 143

Answers (1)

NYC Coder
NYC Coder

Reputation: 7604

This should do it:

df.set_index(df.columns, inplace=True)
print(df)

        A       B       C
A  0.6875  0.1923  0.2300
B  0.3887  0.1923  0.5300
C  0.6061  0.2576  0.2474

Upvotes: 2

Related Questions