Python: Read several json files from a folder

后端 未结 5 757
梦谈多话
梦谈多话 2020-12-04 19:50

I would like to know how to read several json files from a single folder (without specifying the files names, just that they are json files).

Also, it

5条回答
  •  醉梦人生
    2020-12-04 20:08

    If turning into a pandas dataframe, use the pandas API.

    More generally, you can use a generator..

    def data_generator(my_path_regex):
        for filename in glob.glob(my_path_regex):
            for json_line in open(filename, 'r'):
                yield json.loads(json_line)
    
    
    my_arr = [_json for _json in data_generator(my_path_regex)]
    

提交回复
热议问题