【发布时间】:2017-12-31 03:00:47
【问题描述】:
我有一个非常大的数据集:7.9 GB 的 CSV 文件。其中80%作为训练数据,剩下的20%作为测试数据。当我加载训练数据(6.2 GB)时,我在第 80 次迭代(第 80 个文件)有MemoryError。这是我在加载数据时使用的脚本:
import pandas as pd
import os
col_names = ['duration', 'service', 'src_bytes', 'dest_bytes', 'count', 'same_srv_rate',
'serror_rate', 'srv_serror_rate', 'dst_host_count', 'dst_host_srv_count',
'dst_host_same_src_port_rate', 'dst_host_serror_rate', 'dst_host_srv_serror_rate',
'flag', 'ids_detection', 'malware_detection', 'ashula_detection', 'label', 'src_ip_add',
'src_port_num', 'dst_ip_add', 'dst_port_num', 'start_time', 'protocol']
# create a list to store the filenames
files = []
# create a dataframe to store the contents of CSV files
df = pd.DataFrame()
# get the filenames in the specified PATH
for (dirpath, dirnames, filenames) in os.walk(path):
''' Append to the list the filenames under the subdirectories of the <path> '''
files.extend(os.path.join(dirpath, filename) for filename in filenames)
for file in files:
df = df.append(pd.read_csv(filepath_or_buffer=file, names=col_names, engine='python'))
print('Appending file : {file}'.format(file=files[index]))
pd.set_option('display.max_colwidth', -1)
print(df)
在 6.2 GB 的 CSV 文件中有 130 个文件。
【问题讨论】:
-
如何处理 TB 级数据?
标签: pandas machine-learning tensorflow dataset data-processing