簡體   English   中英

熊貓數據框中的前導0

[英]Leading 0 in pandas dataframe

我已經花了幾個小時撓頭,即使試圖在SO和其他地方找到解決方案后,我似乎也找不到找到在熊貓數據框中刪除“ 0”或將索引設置為我的第一個方法的方法。我從數組創建的數組中的項目。 基本上,我試圖將其轉換為熊貓,並使用它插入mysql db。

數組

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

將此數組轉換為pandas 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

似乎您需要創建Series ,因為DataFrame始終具有列名,默認第一DataFrame 0

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM