-1

i have never worked with json files and my problem is I have several folders tar.gz containing different json files. From each zipped folders I need to read only files AAjson, append and convert to a pandas dataframe. I tried in this way

import os, re
import pandas as pd

import pandas as pd 
import tarfile
import json
from pandas.io.json import json_normalize

cd = "my_path"

dfList = []

for root, dirs, files in os.walk(cd):
 with tarfile.open("dirs", "r:*") as tar:
    for fname in files:
        if re.match("AA_*.json$", fname):
            data = json.load(fname)
            frame = pd.DataFrame.from_dict(json_normilized(data), 
orient='columns')
            dfList.append(frame)    

 df = pd.concat(dfList) 

I found the error

FileNotFoundError: [Errno 2] No such file or directory: 'dirs'

Annalix
  • 470
  • 2
  • 6
  • 17

1 Answers1

2
import pandas as pd
data = pd.read_json('filepath/filename')
data
M_S_N
  • 2,764
  • 1
  • 17
  • 38