0

Can someone help me out with the following:

I have a folder that contains levels of sub folders, which each contain several json files. I have been using the following code to extract them all and join them into a dataframe:

PATH = ("C:/Users/77901898/Documents/.../11 - Trial run")
EXT = ("*.json")

json_files = []
for path, subdir, files in os.walk(PATH):
    for file in glob(os.path.join(path, EXT)):
        json_files.append(file)

df = pd.concat([pd.read_json (file) for file in json_files], ignore_index = True)

But I am getting the following error: "If using all scalar values, you must pass an index"

I have also tried the implementation from this question: How to read multiple json files into pandas dataframe? but it throws up "ValueError: No objects to concatenate"

Jasper_97
  • 27
  • 4
  • always put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Dec 09 '21 at 15:51
  • It's possible that you are not getting the right json filename when you do `glob(os.path.join(path, EXT))` try to print the value of `file`. According to os.walk documentation "To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name)." IN your case, the variable names would be path and files https://docs.python.org/3/library/os.html#os.walk – Gonzalo Odiard Dec 15 '21 at 15:59

0 Answers0