i have a dataframe df which has 2 rows and 3 columns a,b,c like below :
A B C
0 1.1 1.2 1.3
1 3.1 3.5 3.9
Required output :I want like below without needing column headers
0 1.1
1.2
1.3
1 3.1
3.5
3.9
Let's first create the dataframe that OP is using
import pandas as pd
df = pd.DataFrame(data=[[1.1, 1.2, 1.3], [3.1, 3.5, 3.9]], columns=['A', 'B', 'C'])
Now, in order to convert the columns into rows, this has a special name "transposition", and one can use dataframe.transpose
as follows
df = df.transpose()
or dataframe.T
(T
is an accessor for the transpose
method)
df = df.T
The final result is
print(df)
[Out]:
0 1
A 1.1 3.1
B 1.2 3.5
C 1.3 3.9
Given this new requirement that OP mentioned, if one wants to concat the second column under the first column, the following will do the work
df = df[0].append(df[1]).reset_index(drop=True)
print(df)
[Out]:
0 1.1
1 1.2
2 1.3
3 3.1
4 3.5
5 3.9