我正在尝试读取以下数据集并将其转换为熊猫数据帧:
https://www.kaggle.com/marlesson/meli-data-challenge-2020
它是一个包含以下格式行的文件:
{'event_info': '...', 'event_timestamp': '...', 'event_type': '...'}
{'event_info': '...', 'event_timestamp': '...', 'event_type': '...'}
{'event_info': '...', 'event_timestamp': '...', 'event_type': '...'}
我一直在尝试以下方法,但时间太长(+60分钟):
import numpy as np
import pandas as pd
import fileinput
import json
%%time
df = pd.DataFrame()
with fileinput.input(files='/kaggle/input/meli-data-challenge-2020/train_dataset.jl') as file:
for line in file:
conv = json.loads(line)
df = df.append(conv, ignore_index=True)
df.head()
在这段代码中,它以字符串的形式逐行读取文件,将每个文件转换为json,然后将其附加到数据帧中。
有没有办法更快地将数据集转换为数据帧
我试图读取的文件是一个包含多个对象的JSON文件。Pandas
read_json()
支持类似以下数据的lines
参数:相关问题 更多 >
编程相关推荐