This is the data :
Calendar years 1990 1991 1992 ...
Angola 84 71 80 ...
. . . .
. . . .
. . . .
Both rows and columns have more data, this is just a sample data
I want the data to look like :
Calendar years Angola ...
1990 84
1991 71
1992 80
. .
. .
. .
I used df.transpose() but it doesn't change the column headings, and instead puts the column headings as 0,1,2..
Any leads will be appreciated
CodePudding user response:
This is what you could do:
df = df.T.reset_index()
df.columns = df.iloc[0, :]
df = df.drop(0)
Output:
Calendar years Angola
1 1990 84
2 1991 71
3 1992 80