Converting Time series Df with Time variable as columns from wide to long

Question:

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       
Asked By: George Robbin

||

Answers:

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()
Answered By: tehCheat
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.