Convert List to Pandas Dataframe Column

StackOverflow

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"]

Required Pandas DF (shape =3,):

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

Please note the numbers represent index in Required Pandas DF above.

Answer rating: 197

Use:

L = ["Thanks You", "Its fine no problem", "Are you sure"]

#create new df 
df = pd.DataFrame({"col":L})
print (df)

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

df = pd.DataFrame({"oldcol":[1,2,3]})

#add column to existing df 
df["col"] = L
print (df)
   oldcol                  col
0       1           Thanks You
1       2  Its fine no problem
2       3         Are you sure

Thank you DYZ:

#default column name 0
df = pd.DataFrame(L)
print (df)
                     0
0           Thanks You
1  Its fine no problem
2         Are you sure




Get Solution for free from DataCamp guru