Trying to expand row data and convert to DataFrame, getting this error: AttributeError: 'float' object has no attribute 'keys'
Trying to expand row data and convert to DataFrame, getting this error: AttributeError: 'float' object has no attribute 'keys'
当 运行 我的函数如下时,我遇到了以下错误:
AttributeError: 'float' 对象没有属性 'keys'
每行包含以下数据:
{'volume': '8579152.41', 'price_change': '-0.00211948', 'price_change_pct': '-0.0016', 'volume_change': '445336.65', 'volume_change_pct': '0.0548', 'market_cap_change': '-2813342.71', 'market_cap_change_pct': '-0.0016'}
def adj_col(data,column_name): # Function to expand columns open up brace brackets and then converts it to a DataFrame
convert = data.pop(column_name).values.tolist()
converted = pd.DataFrame(convert)
return converted
我的目标是将数据扩展为一列,完成后将其转换为 DataFrame。
我做错了什么?
您可能在该列的某处有 NaN
个值。此示例将过滤掉 NaN
值:
convert = df.pop("Values").values.tolist()
converted = pd.DataFrame([v for v in x if pd.notna(v)]) # <-- filter out the NaN values
print(converted)
当 运行 我的函数如下时,我遇到了以下错误: AttributeError: 'float' 对象没有属性 'keys'
每行包含以下数据:
{'volume': '8579152.41', 'price_change': '-0.00211948', 'price_change_pct': '-0.0016', 'volume_change': '445336.65', 'volume_change_pct': '0.0548', 'market_cap_change': '-2813342.71', 'market_cap_change_pct': '-0.0016'}
def adj_col(data,column_name): # Function to expand columns open up brace brackets and then converts it to a DataFrame
convert = data.pop(column_name).values.tolist()
converted = pd.DataFrame(convert)
return converted
我的目标是将数据扩展为一列,完成后将其转换为 DataFrame。
我做错了什么?
您可能在该列的某处有 NaN
个值。此示例将过滤掉 NaN
值:
convert = df.pop("Values").values.tolist()
converted = pd.DataFrame([v for v in x if pd.notna(v)]) # <-- filter out the NaN values
print(converted)