2017-03-16 222 views
0

我一直在抓我的頭幾個小時,甚至試圖找到SO和其他地方的解決方案後,我似乎無法找到在下降「0」的方式大熊貓據幀或者設置索引數組我的第一個項目,我從一個陣列創建。基本上,我想這個轉換成大熊貓,並用它插入到MySQL數據庫。在大熊貓數據幀前導0

陣列

[u'Thu Mar 16 11:52:48 +0000 2017', u'Best Women Nice Shorts & Shirt Free Shipping Xintown Road Bike Travel Clothes', 0, 0] 

代碼轉換這個數組大熊貓DF

df = pd.DataFrame(tweet) 
print (df) 
df.to_sql(con=connection, name=table_name, if_exists='append', flavor='mysql') 

輸出:

           0 
1 Best Women Nice Shorts & Shirt Free Shippi... 
2             0 
3             0 

回答

1

看來你需要創建Series,因爲DataFrame始終列名,默認的第一列是0

s = pd.Series(tweet) 
print (s) 
1 Best Women Nice Shorts & Shirt Free Shippi... 
2             0 
3             0 
dtype: object 
+0

我可以使用該系列上傳數據到sql嗎? – user6083088

+0

是的,使用['Series.to_sql'](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.to_sql.html) – jezrael

+0

謝謝你的幫助,非常感謝。猜猜我已經加載學習。我沒有試過Series.tosql,但我會接受你的答案。 (PS:不能接受的答案在5分鐘 - 所以才提示,但在此時間之後,我會做) – user6083088