Convert pandas Series to DataFrame

前端 未结 6 991
长情又很酷
长情又很酷 2020-11-27 11:08

I have a Pandas series sf:

email
email1@email.com    [1.0, 0.0, 0.0]
email2@email.com    [2.0, 0.0, 0.0]
email3@email.com    [1.0, 0.0, 0.0]
email4@email.com         


        
6条回答
  •  庸人自扰
    2020-11-27 11:47

    Series.to_frame can be used to convert a Series to DataFrame.

    # The provided name (columnName) will substitute the series name
    df = series.to_frame('columnName')
    

    For example,

    s = pd.Series(["a", "b", "c"], name="vals")
    df = s.to_frame('newCol')
    print(df)
    
       newCol
    0    a
    1    b
    2    c
    

提交回复
热议问题