Convert List to Pandas Dataframe Column

前端 未结 5 1477
别跟我提以往
别跟我提以往 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:18

    Example:

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

    code block:

    import pandas as pd
    df = pd.DataFrame(lst)
    

    Output:

        0
    0   Thanks You
    1   Its fine no problem
    2   Are you sure
    

    It is not recommended to remove the column names of the panda dataframe. but if you still want your data frame without header(as per the format you posted in the question) you can do this:

    df = pd.DataFrame(lst)    
    df.columns = ['']
    

    Output will be like this:

    0   Thanks You
    1   Its fine no problem
    2   Are you sure
    

    or

    df = pd.DataFrame(lst).to_string(header=False)
    

    But the output will be a list instead of a dataframe:

    0           Thanks You
    1  Its fine no problem
    2         Are you sure
    

    Hope this helps!!

提交回复
热议问题