将列表转换为Pandas Dataframe列 [英] Convert List to Pandas Dataframe Column

查看:673
本文介绍了将列表转换为Pandas Dataframe列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将列表转换为一列pandas数据框

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

当前列表(len = 3):

Current List (len=3):

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

必需的熊猫DF(形状= 3,):

Required Pandas DF (shape =3,):

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

请注意,数字代表上面的必需熊猫" DF中的索引.

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

推荐答案

使用:

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

谢谢您 DYZ :

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

这篇关于将列表转换为Pandas Dataframe列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆