我正在尝试从Kaggle中读取expedia数据,它包含一个4 4GB的csv文件,我尝试使用pd.read_csv('filename')
读取它,但得到了内存错误。第二种方法,我尝试只使用下面的代码读取特定的列:
pd.read_csv('train.csv', dtype={'date_time':np.str, user_location_country': np.int32, 'user_location_region':np.int32, 'user_location_city':np.int32, 'orig_destination_distance':np.float64, 'user_id':np.int32})
这再次给出了内存错误,但使用了相同方法的另一个修改,即:
train = pd.read_csv('train.csv', dtype={'user_id':np.int32,'is_booking':bool, 'srch_destination_id':np.int32, 'hotel_cluster':np.int32}, usecols=['date_time', 'user_id', 'srch_ci', 'srch_co', 'srch_destination_id', 'is_booking', 'hotel_cluster'])'
在大约5分钟内读取数据。
我的问题是,我想使用这两种方法读取更多的列,但都失败了,并给出了Memory error
。我使用8 8GB的RAM和8 8GB的交换空间,所以只读取24列数据中的7-8列将减少大约800MB的数据大小,所以在硬件使用上没有问题。我还试着根据后面要读的算法,一块块地读我不想读的内容。
发布于 2017-11-14 21:56:38
不幸的是,读取csv文件需要比它在磁盘上的大小更多的内存(我不知道多多少)。
您可以找到另一种方法来处理您的文件here
https://stackoverflow.com/questions/47287135
复制相似问题