简体   繁体   中英

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

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 . To remove the warning specify the default data type when instantiating the Series in your code.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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