2017-04-04 65 views

回答

5

您可以使用splitDataFrame構造:

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 
+0

其1行6列 我想1個6行。 –

+0

df.T會轉置它。 –

+0

請檢查編輯的答案 – jezrael

相關問題