繁体   English   中英

使用 dtype 将 dataframe 从 float64 转换为 object

[英]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 日)

无法从 dtype('

[英]Cannot cast array data from dtype('<M8[ns]') to dtype('float64') according to the rule 'safe'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM