I am trying to convert a Times series df to long format however the years are in columns rather than rows. i have tried both .pivot and .melt but cant get to desired layout included code and example table below.
map_df = pd.read_csv('https://raw.githubusercontent.com/GeorgeRobbin/GeorgeRobbin.github.io/main/Delinnquency_MAP.csv')
map_df1 = melt(map_df(wide), id.vars = c("name"), variable.name = "date"
current layout
Name 2008-01 2008-02
California x x
New York x x
desired layout
date California New York
2008-01 x x
2008-02 x x
CodePudding user response:
pandas.Dataframe.transpose
works.
import pandas as pd
map_df = pd.read_csv('https://raw.githubusercontent.com/GeorgeRobbin/GeorgeRobbin.github.io/main/Delinnquency_MAP.csv')
map_df = map_df.transpose()