如何将CSV数据读取到NumPy中的记录数组中? [英] How do I read CSV data into a record array in NumPy?
本文介绍了如何将CSV数据读取到NumPy中的记录数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有直接方法将CSV文件的内容导入到记录数组中,就像R的read.table()
,read.delim()
和read.csv()
系列将数据导入到R的数据帧中一样?
I wonder if there is a direct way to import the contents of a CSV file into a record array, much in the way that R's read.table()
, read.delim()
, and read.csv()
family imports data to R's data frame?
或者是使用 csv.reader()<<的最佳方法/a>,然后应用类似numpy.core.records.fromrecords()
的内容?
推荐答案
您可以通过将delimiter
kwarg设置为逗号来使用Numpy的genfromtxt()
方法.
You can use Numpy's genfromtxt()
method to do so, by setting the delimiter
kwarg to a comma.
from numpy import genfromtxt
my_data = genfromtxt('my_file.csv', delimiter=',')
有关该功能的更多信息,请参见其各自的文档.
More information on the function can be found at its respective documentation.
这篇关于如何将CSV数据读取到NumPy中的记录数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文