Expand pandas DataFrame column into multiple rows

前端 未结 7 1591
星月不相逢
星月不相逢 2020-12-05 04:50

If I have a DataFrame such that:

pd.DataFrame( {\"name\" : \"John\", 
               \"days\" : [[1, 3, 5, 7]]
              })
<
相关标签:
7条回答
  • 2020-12-05 05:47

    Probably somehow like this:

    df2 = pd.DataFrame(columns = df.columns)
    for i,r in df.iterrows():
        for e in r.days:
            new_r = r.copy()
            new_r.days = e
            df2 = df2.append(new_r)
    df2
    
    0 讨论(0)
提交回复
热议问题