[英]How to load a large JSON file to a Pandas Dataframe
我有 16 個 JSON 文件,每個文件的大小約為 14GB。 我嘗試了以下方法逐行閱讀它們。
with open(file_name, encoding="UTF-8") as json_file:
cursor = 0
for line_number, line in enumerate(json_file):
print ("Processing line", line_number + 1,"at cursor index:", cursor)
line_as_file = io.StringIO(line)
# Use a new parser for each line
json_parser = ijson.parse(line_as_file)
for prefix, type, value in json_parser:
#print ("prefix=",prefix, "type=",type, "value=",value,ignore_index=True)
dfObj = dfObj.append({"prefix":prefix,"type":type,"value":value},ignore_index=True)
cursor += len(line)
我的目標是將它們加載到 pandas 數據幀中以執行一些搜索操作。
問題是這種方法需要花費大量時間來讀取文件。
有沒有其他最佳方法來實現這一目標?
您可以使用 Pandas 內置 function
pandas.read_json()
文檔在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.