Convert List to Pandas Dataframe Column

前端 未结 5 1471
别跟我提以往
别跟我提以往 2020-12-02 05:34

I need to Convert my list into a one column pandas dataframe

Current List (len=3):

[\'Thanks You\',
 \'Its fine no problem\',
 \'Are you sure\']
         


        
5条回答
  •  暖寄归人
    2020-12-02 06:09

    if your list looks like this: [1,2,3] you can do:

    lst = [1,2,3]
    df = pd.DataFrame([lst])
    df.columns =['col1','col2','col3']
    df
    

    to get this:

        col1    col2    col3
    0   1       2       3
    

    alternatively you can create a column as follows:

    import numpy as np
    df = pd.DataFrame(np.array([lst]).T)
    df.columns =['col1']
    df
    

    to get this:

      col1
    0   1
    1   2
    2   3
    

提交回复
热议问题