简体   繁体   English

使用 pandas.io.json.json_normalize 获取“AttributeError: 'float' object has no attribute 'items'”

[英]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.

相关问题 pandas.io.json.json_normalize 非常嵌套 json - pandas.io.json.json_normalize with very nested json 将pandas.io.json.json_normalize()与空列表属性一起使用 - Using pandas.io.json.json_normalize() with empty list attributes pyspark 数据框中是否有类似于 pandas.io.json.json_normalize 的函数 - Is there a function in pyspark dataframe that is similar to pandas.io.json.json_normalize Python / Pandas using pandas.io.json.json_normalize to drill down in json - Python / Pandas using pandas.io.json.json_normalize to drill down in json 获取 AttributeError:模块“pandas”在调用方法“访问 OutbreakLocation 数据”时没有属性“json_normalize” - Getting AttributeError: module 'pandas' has no attribute 'json_normalize' while calling method “Access OutbreakLocation data” 获取属性错误:模块“熊猫”没有属性“json_normalize” - Getting attribute error : module 'pandas' has no attribute 'json_normalize' AttributeError:“ float”对象在熊猫中没有属性“ split” - AttributeError: 'float' object has no attribute 'split' in pandas Pandas: AttributeError: 'float' object 没有属性 'MACD' - Pandas: AttributeError: 'float' object has no attribute 'MACD' 模块“熊猫”没有属性“json_normalize” - module 'pandas' has no attribute 'json_normalize' Pandas: AttributeError: 'float' object 没有属性 'isnull' - Pandas: AttributeError: 'float' object has no attribute 'isnull'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM