[英]Getting " AttributeError: 'float' object has no attribute 'items' " with pandas.io.json.json_normalize
When trying to normalize a series within a pandas dataframe with the json_normalize
function i am getting the Error:当尝试使用json_normalize
函数对json_normalize
数据json_normalize
的系列进行标准化时,出现错误:
"AttributeError: 'float' object has no attribute 'items'"
Each row of the series contains a nested json, though some rows don't contain all of the attributes, that are present in some of those json' from that series该系列的每一行都包含一个嵌套的 json,尽管有些行不包含该系列的某些 json' 中存在的所有属性
also there is a field "timestamp":{"$date":1578411194000}
within those nested json's, which is also present in another column of that same dataframe, giving me an error in another attempt to flatten that other series.在那些嵌套的 json 中还有一个字段"timestamp":{"$date":1578411194000}
,它也出现在同一数据帧的另一列中,这给了我另一个试图展平其他系列的错误。
I am assuming the AttributeError
has something to do with the either not all JSONs containing all the fields or sth.我假设AttributeError
与不是所有包含所有字段的 JSON 或某事有关。 with those timestamps.json_normalize
did work for some of the other df-columns.使用这些timestamps.json_normalize
确实适用于其他一些 df 列。
I hope this is enough info.我希望这是足够的信息。 thanks a lot in advance!非常感谢!
It can happen if there are NaN fields which can be solved by using dropna()
:如果存在可以使用dropna()
解决的 NaN 字段,则可能会发生这种情况:
pd.json_normalize(df.explode("field")["field"]))
=> AttributeError: 'float' object has no attribute 'items'
pd.json_normalize(df.explode("field")["field"].dropna())
=> no error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.