Converting a dictionary with lists for values into a dataframe

前端 未结 2 1991
离开以前
离开以前 2021-01-18 00:24

I spent a while looking through SO and seems I have a unique problem.

I have a dictionary that looks like the following:

dict={
    123: [2,4],
    2         


        
2条回答
  •  梦毁少年i
    2021-01-18 01:15

    You can either preprocess the data as levi suggests, or you can transpose the data frame after creating it.

    testdict={
        123: [2,4],
        234: [6,8],
        456: [10, 12]
    }
    df = pd.DataFrame(testdict)
    df = df.transpose()
    
    print(df)
    #      0  1
    # 123  2  4
    # 234  6  8
    

提交回复
热议问题