【问题标题】:Pandas Reading json gives me ValueError: Invalid file path or buffer object type in Ploty DashPandas Reading json 给了我 ValueError: Invalid file path or buffer object type in Plotly Dash
【发布时间】:2020-11-07 08:42:29
【问题描述】:

这一行:

        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 在一个回调中,并在另一个回调中获取它。如何解决此错误?

【问题讨论】:

    标签: json pandas plotly-dash


    【解决方案1】:

    当我读取我用 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))
    

    【讨论】:

      猜你喜欢
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 2019-04-22
      • 2022-12-02
      • 2022-12-27
      • 1970-01-01
      相关资源
      最近更新 更多