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"

2
  • 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. Commented Dec 9, 2021 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 docs.python.org/3/library/os.html#os.walk Commented Dec 15, 2021 at 15:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.