Pandas Reading json gives me ValueError: Invalid file path or buffer object type in Ploty Dash
Pandas Reading json gives me ValueError: Invalid file path or buffer object type in Ploty Dash
这一行:
else:
#add to this
nutrients_totals_df = pd.read_json(total_nutrients_json, orient='split')
正在抛出错误。
我把我的 json 写成这样:
nutrients_json = nutrients_df.to_json(date_format='iso', orient='split')
然后我将其隐藏在一个回调中的 div 或 dcc.Storage
中,并在另一个回调中获取它。我该如何解决这个错误?
当我读取用 Pandas 编写的 json 文件时,我使用下面的函数并在 json.loads() 内部调用。
def read_json_file_from_local(fullpath):
"""read json file from local"""
with open(fullpath, 'rb') as f:
data = f.read().decode('utf-8')
return data
df = json.loads(read_json_file_from_local(fullpath))
这一行:
else:
#add to this
nutrients_totals_df = pd.read_json(total_nutrients_json, orient='split')
正在抛出错误。 我把我的 json 写成这样:
nutrients_json = nutrients_df.to_json(date_format='iso', orient='split')
然后我将其隐藏在一个回调中的 div 或 dcc.Storage
中,并在另一个回调中获取它。我该如何解决这个错误?
当我读取用 Pandas 编写的 json 文件时,我使用下面的函数并在 json.loads() 内部调用。
def read_json_file_from_local(fullpath):
"""read json file from local"""
with open(fullpath, 'rb') as f:
data = f.read().decode('utf-8')
return data
df = json.loads(read_json_file_from_local(fullpath))