Python 将字符串中的每个单词读入新行

Python 将字符串中的每个单词读入新行,python,pandas,dataframe,Python,Pandas,Dataframe,我有一根绳子。 msg='IMF董事总经理' 我想要像下面这样的数据帧 ['The' “管理” “董事” “当然” “这个” “国际货币基金组织” ] 1列和6行。您可以与DataFrame构造函数一起使用: msg='The managing director of the IMF' df = pd.DataFrame(msg.split(), columns=['col']) print (df) col 0 The 1 managing 2 director

我有一根绳子。 msg='IMF董事总经理' 我想要像下面这样的数据帧 ['The' “管理” “董事” “当然” “这个” “国际货币基金组织” ] 1列和6行。

您可以与
DataFrame
构造函数一起使用:

msg='The managing director of the IMF'
df = pd.DataFrame(msg.split(), columns=['col'])
print (df)
        col
0       The
1  managing
2  director
3        of
4       the
5       IMF

备选方案:

msg='The managing director of the IMF'
L = msg.split()
df = pd.DataFrame(np.array(L).reshape(-1, len(L)), columns=list('abcdef'))
print (df)
     a         b         c   d    e    f
0  The  managing  director  of  the  IMF
您可以与
DataFrame
构造函数一起使用:

msg='The managing director of the IMF'
df = pd.DataFrame(msg.split(), columns=['col'])
print (df)
        col
0       The
1  managing
2  director
3        of
4       the
5       IMF

备选方案:

msg='The managing director of the IMF'
L = msg.split()
df = pd.DataFrame(np.array(L).reshape(-1, len(L)), columns=list('abcdef'))
print (df)
     a         b         c   d    e    f
0  The  managing  director  of  the  IMF

它的1行6列我想要1列6行。df.T会转置它。@AshishBainade-很高兴能帮助你。如果我的答案有用,别忘了。谢谢。它是1行6列。我想要1列6行。df.T会转置它。@AshishBainade-很高兴能帮助你。如果我的答案有用,别忘了。非常感谢。