transpose pandas dataframe code example
Example 1: transpose of dataframe
result = df.transpose()
Example 2: append to pandas dataframe
df = df.append({'index1': value1, 'index2':value2,...}, ignore_index=True)
Example 3: append dataframe pandas
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
>>> df
A B
0 1 2
1 3 4
>>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
>>> df.append(df2)
A B
0 1 2
1 3 4
0 5 6
1 7 8
Example 4: dataframe index column invert
You're looking for the transpose (T) method
In [11]: df
Out[11]:
10 20 30 70
data1: 2.3 5 6 7
In [12]: df.T
Out[12]:
data1:
10 2.3
20 5.0
30 6.0
70 7.0
Example 5: dataframe index column invert
In [11]: df
Out[11]:
10 20 30 70
data1: 2.3 5 6 7
In [12]: df.T
Out[12]:
data1:
10 2.3
20 5.0
30 6.0
70 7.0