Python:分块读取大文件
Python中读取文件的方式有许多种,往往数据量大的情况令人苦恼。之前一篇博客https://www.cnblogs.com/xiaolan-Lin/p/12014686.html我说会发大文件读取的后续。
那么后续来啦!
import pandas as pd # 采用块读取功能,读取csv文件 path1 = "./data\\tianchi_mobile_recommend_train_user.csv" file1 = open(path1) user_data = pd.read_csv(path1, sep=‘,‘, iterator=True) loop = True chunkSize = 1000 chunks1 = [] while loop: try: chunk1 = user_data.get_chunk(chunkSize) chunks1.append(chunk1) except StopIteration: loop = False user_data = pd.concat(chunks1, ignore_index=True)
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16