Imagine there are three JSON files in a nested folder under data folder.
$ tree data
data
├── date1
│ ├── date2
│ │ └── file1_date2.json
│ └── file1.json
└── file1.json
glob2 module can be used to fetch the JSON files recursively. glob returns a list of files.
from glob2 import glob
jsonFiles = glob('data/**/*.json') #Can be used absolute or relative paths
print(jsonFiles)
['data/file1.json', 'data/date1/file1.json', 'data/date1/date2/file1_date2.json']
JSON files ban be loaded into dataframe by iterating thru the list jsonFiles .
dfList = []
for jsonFile in jsonFiles:
df = pd.read_json(jsonFile)
dfList.append(df)
dfTrainingDF = pd.concat(dfList, axis=0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.