python3 文件读取方式

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]

上一篇:prim算法


下一篇:Python3中变量引用对象-如何防止原始数据被修改