[英]to_dict('records') causing unsupported type: <class 'str'> error
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.