Reputation:
I have result my data frame as below. How to convert into rows. My column header is numbers which has to avoided
https://i.sstatic.net/RvwVD.png
Upvotes: 0
Views: 39
Reputation: 854
If I understand you correctly, you want to turn your first row into your header?
This is the way I would do it:
df.T.set_index(0).T
Upvotes: 0
Reputation: 153510
IIUC, try this:
row = [*'ABCDE']
row2 = [1,2,3,4,5]
df = pd.DataFrame([row,row2])
print(df)
Input dataframe:
0 1 2 3 4
0 A B C D E
1 1 2 3 4 5
Use this code:
df_out = df.T.set_index(0)
print(df_out)
Output:
1
0
A 1
B 2
C 3
D 4
E 5
Upvotes: 1
Reputation: 301
you can use a simple reshape to do this.
This can be many other ways to do this, Here I show I way,
I think this is how your data frame looks like:
**df = pd.DataFrame({0:['neg',0.015],1:['neu',0.006],2:['pos',0.014]})**
You can do a simple reshape using below line: **
import pandas as pd
import numpy as np
pd.DataFrame(np.array(df.iloc[1:]).reshape(-1,1))
**
Upvotes: 0