Home > Enterprise >  i was trying to run the code and im still getting same error value error invalid file or buffer
i was trying to run the code and im still getting same error value error invalid file or buffer

Time:08-10

import json 
import pandas as pd 
with open(r'C:\Users\hp\Downloads\vertpoal.com_vv.json')as d:
    dictData=json.load(d) 
df=pd.read_json(dictData) 

and I'm getting error:

ValuErorr: invalid file path or buffer object type;<class 'dict'>

CodePudding user response:

Try:

df = pd.DataFrame.from_dict(dictData)

CodePudding user response:

json.load transforms JSON to a python dict which is redundant, because pd.read_json expects 'a valid JSON str, path object or file-like object' (https://pandas.pydata.org/docs/reference/api/pandas.read_json.html)

import pandas as pd 
with open(r'C:\Users\hp\Downloads\vertpoal.com_vv.json')as d:
    df=pd.read_json(d)
# some further actions with df object.

You should be able to access df variable outside of with scope.

  • Related