1
我有下面的字符串。 MSG = 我想熊貓數據幀像下面 [ '的' '管理' '導演' '的' 'IMF' '的' ] 1列 '的IMF的總經理' & 6行。將字符串中的每個單詞讀入熊貓新行
我有下面的字符串。 MSG = 我想熊貓數據幀像下面 [ '的' '管理' '導演' '的' 'IMF' '的' ] 1列 '的IMF的總經理' & 6行。將字符串中的每個單詞讀入熊貓新行
您可以使用split
與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
df = pd.DataFrame([msg.split()], columns=list('abcdef'))
print (df)
a b c d e f
0 The managing director of the 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會轉置它。 –
請檢查編輯的答案 – jezrael