简体   繁体   English

使用 dtype 将 dataframe 从 float64 转换为 object

[英]converting a dataframe from float64 to object using dtype

I have written this function long time but when i tried it now im getting an error message我已经写了这个 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()

and i get this error message我收到此错误消息

"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."

im not really sure how to resolve this issue, i appreciate if i could get any help.我不确定如何解决这个问题,如果我能得到任何帮助,我将不胜感激。 thanks谢谢

Just had this problem myself.我自己刚遇到这个问题。

As the error warning suggests, for empty series the default will be object rather than float64 .正如错误警告所暗示的,对于空系列,默认object而不是float64 To remove the warning specify the default data type when instantiating the Series in your code.要删除警告,请在代码中实例化 Series 时指定默认数据类型。

Try this code:试试这个代码:

df = pd.concat([pd.Series(v, name=k, dtype = 'object') for k, v in d.items()], axis=1)

Documentation at this link: What's new in 1.0.0 (January 29, 2020)此链接中的文档: 1.0.0 中的新增功能(2020 年 1 月 29 日)

暂无
暂无

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

相关问题 如何使用 python 将列中的 dtype 从 object 更改为 float64? - How can i change dtype from object to float64 in a column, using python? 将dtype = object的数据结构转换为dtype = float64的numpy数组 - Converting a data structure of dtype=object to numpy array of dtype=float64 pandas 未将 object dtype 转换为 float64,即使在 df.astype('float64') 无错误执行后也是如此 - pandas not converting an object dtype to float64 even after error free execution of df.astype('float64') 在 DataSeries 中将 Dtype“object”更改为 Dtype“float64” - Changing Dtype "object" to Dtype "float64" in DataSeries 从其他数据帧中分配一个数字 - Series([], Name: id, dtype: float64) - Attribuate a number from an other Dataframe - Series([], Name: id, dtype: float64) ValueError:使用KNeighborsRegressor的拟合,输入包含NaN,无穷大或对于dtype(&#39;float64&#39;)而言太大的值 - ValueError: Input contains NaN, infinity or a value too large for dtype('float64') using fit from KNeighborsRegressor 将 float64 转换为日期 - Converting float64 to Date TypeError:无法从dtype(&#39; - TypeError: Cannot cast array data from dtype('<U1') to dtype('float64') according to rule 'safe' 根据规则&#39;safe&#39;,无法将数组数据从dtype(&#39;float64&#39;)转换为dtype(&#39;int32&#39;) - Cannot cast array data from dtype('float64') to dtype('int32') according to the rule 'safe' 无法从 dtype(&#39; - Cannot cast array data from dtype('<M8[ns]') to dtype('float64') according to the rule 'safe'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM