从这里下载一些数据: http://insideairbnb.com/get-the-data.html
然后
listings = pd.read_csv('listings.csv')
尝试更改类型
listings.bathrooms = listings.bathrooms.astype('int64',errors='ignore')
listings.bedrooms = listings.bedrooms.astype('int64',errors='ignore')
listings.beds = listings.beds.astype('int64',errors='ignore')
listings.price = listings.price.replace('[\$,]','',regex=True).astype('float')
listings.price = listings.price.astype('int64',errors='ignore')
尝试了一些其他的组合,但最后出现了错误或只是没有改变数据类型
编辑:更正了一些打字错误
最后一行中的撇号位置不正确,最后一行的类型也不正确:您需要“而不是”。(可能是由于代码块的原因意外添加的)
所以对我来说,它是这样工作的:
但如果要将其重新分配给原始变量,则需要与前几行中使用的结构相同:
相关问题 更多 >
编程相关推荐