![](/img/trans.png)
[英]How can i change dtype from object to float64 in a column, using python?
[英]converting a dataframe from float64 to object using dtype
我已經寫了這個 function 很長時間但是當我現在嘗試它時我收到一條錯誤消息
def saveToDisk(i):
print("saving ***")
name='kenos'+str(i)+'.csv'
d = {'adId':adId, 'Title':title,'Price':prices,'Description':description, 'Location':location,'Ddate Posted':datePosted, 'Location':location, 'Features' : features, 'URL':urlToSave, 'Type' : listingType}
df = pd.concat([pd.Series(v, name=k) for k, v in d.items()], axis=1 )
df.to_csv(name,index=False)
resetAll()
我收到此錯誤消息
"df = pd.concat([pd.Series(v, name=k) for k, v in d.items()], axis=1 )
DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning."
我不確定如何解決這個問題,如果我能得到任何幫助,我將不勝感激。 謝謝
我自己剛遇到這個問題。
正如錯誤警告所暗示的,對於空系列,默認object
而不是float64
。 要刪除警告,請在代碼中實例化 Series 時指定默認數據類型。
試試這個代碼:
df = pd.concat([pd.Series(v, name=k, dtype = 'object') for k, v in d.items()], axis=1)
此鏈接中的文檔: 1.0.0 中的新增功能(2020 年 1 月 29 日)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.