I´m trying to transpose the data that I obtained and make the column with Samples as a header What I´m starting with
|Sample 1 | 0,4704 |
----------
|Sample 2 | 0,1501 |
----------
|Sample 3 | 0,4388 |
----------
|Sample 4 | 0,2957|
---------
What I'd like to have
sample 1 |sample 2 |sample 3 |sample 4
----------
0,4704 | 0,1501 | 0,4388 | 0,2957
----------
What I really have
1 |2 |3 |4
----------
sample 1| sample 2 |sample 3 |sample 4
----------
0,4704 | 0,1501 |0,4388 | 0,2957
What I want is to remove those numbers 1,2,3,4 and make sample 1, sample 2... as a header
here is also a link to the screenshot that I made [1]: https://i.stack.imgur.com/G526C.png
What I tried so far is
df2=pd.read_csv('3.dat',sep='\t', header=None)
df2
df2=pd.read_csv('3.dat',sep='\t', header=None)
df2_transponed=df2.T
df2_transponed.to_csv('3_0T.dat', index=[1], header=None, sep='\t')
df2_transponed
Any suggestions would be helpful, thank you
CodePudding user response:
Try setting the column ´0´ as index first
df2.set_index(0).T
CodePudding user response:
What you have done so far works. Just replace the header,
df.columns = df.iloc[1]
df = df.drop(df.index[1])