简体   繁体   English

to_dict('records') 导致不支持的类型:<class 'str'> 错误</class>

[英]to_dict('records') causing unsupported type: <class 'str'> error

error错误

Getting a unsupported type error, just updated pandas and ensured it is runnning version 1.0.3.收到不支持的类型错误,刚刚更新了 pandas 并确保它运行的是 1.0.3 版。 Any ideas?有任何想法吗? Thank you!谢谢!

You are using .to_dict on a Series, which doesn't support the parameter you are passing.您在系列上使用.to_dict ,它不支持您传递的参数。 ( see pandas.Series.to_dict documentation ) 参见pandas.Series.to_dict文档

I think you got confused with the .to_dict from DataFrame which can effectively get records as first parameter.我认为您对.to_dict中的 .to_dict 感到困惑,它可以有效地将records作为第一个参数。 ( see pandas.DataFrame.to_dict documentation ) 参见pandas.DataFrame.to_dict文档

You can just write flatmodel = df[['flat_model']] to make the flatmodel variable a DataFrame (instead of a Series) so that the .to_dict won't fail anymore.您可以编写flatmodel = df[['flat_model']]以使flatmodel变量成为 DataFrame (而不是 Series),这样.to_dict就不会再失败了。

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

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