understanding MultiIndex

后端 未结 2 905
情书的邮戳
情书的邮戳 2021-01-06 06:15

So I have a sample data set like this in csv:-

name    team    date       score
John    A   3/9/12      100
John    B   3/9/12      99
Jane    B   4/9/12             


        
2条回答
  •  走了就别回头了
    2021-01-06 06:42

    as an alternative solution, if -for whatever reason- you want to keep the multi-indexing in the read_csv statement.

    Same dataset.

    df = pd.read_csv("Workbook1.csv", index_col=["team", "name"])
    df.stack().unstack()
    
            date    score
    team    name        
    A   John    3/9/2012    100
        Peter   9/9/2012    103
        Rachel  30/10/12    98
    B   Jane    4/9/2012    102
        John    3/9/2012    99
        Kate    31/10/12    103
    C   David   1/11/2012   104
        Josie   11/9/2012   111
    

提交回复
热议问题