numpy.load_txt() 遍历每一行速度快
path = 'xxx'
# df = pd.read_csv(path, sep=',')
# 使用numpy 遍历每一行更快
dataset = np.loadtxt(path, dtype=np.str_, delimiter=',')
data = dataset.tolist()
for item in data:
print(item[0],end=' ')
print(item[1],end=' ')
print(item[2])
pandas .read_csv() 单纯读取文件速度快
path = 'xxx'
df = pd.read_csv(path, sep='\t')
for idx in df.index:
city = df['city'][idx]
bed = df['bed'][idx]
people_num = df['population'][idx]