I have a dataframe as below:
import pandas as pd
df_vals = {'A':['X','Y','Z','X','Y','Z'],
'B':[23,12,68,2,6,15],
'C':[34,11,256,321,138,56],
'D':['02-Feb-14', '04-Mar-14', '23-Jan-13', '18-Feb-14', '02-Jun-14', '04-Aug-13']
}
# Creating the DataFrame
df = pd.DataFrame(data=df_vals)
print(df) # Prints the created dataframe
I used the below code:
# Way : 1
df1_transposed = df.T
print(df1_transposed)
This is not returning the results as expected.
Neither the below code :
# Way : 2
df2_transposed = df.transpose()
print(df2_transposed)
What I want to transpose the data to look something like in the below snapshot:
