Numpy.genfromtxt-读取csv文件数据

list不是真正的数组,处理大量数据时比较慢,numpy内置函数处理数据时较快

Numpy.genfromtxt

A very common file format for data file is comma-separated values (CSV), or related formats such as TSV (tab-separated values). To read data from such files into Numpy arrays we can use the numpy.genfromtxt function.

 

>>> import numpy as np
>>> data = np.genfromtxt('data.csv',delimiter=',') #delimiter: the str used to separate data. 
>>> data[0:3,]
array([[32.50234527, 31.70700585],
       [53.42680403, 68.77759598],
       [61.53035803, 62.5623823 ]])

参考:Python科学计算——Numpy.genfromtxt

你可能感兴趣的:(python)