我一直在尝试使用NumPy
模块解析CSV文件,如下所示,我必须硬编码dtype
,如下所示。你知道吗
def FileR(self,FileName):
data = [('SecurityInfo', 'S64'),
('Date', 'S64'),
('Cost', 'float'),
('Yield', 'float'),]
return data
def Gettheinfo(self):
the_info = np.loadtxt('the.csv', delimiter=',', skiprows = 1, dtype = self.FileR('the.csv'))
return the_info
有没有办法不用硬编码来使用np.loadtxt
?你知道吗
谢谢
我不知道你的文件是如何格式化的,但我假设它看起来像这样:
然后可以使用^{} ,它更强大:
dtype=None
将自动确定每个列的数据类型。你知道吗names=True
将从文件的第一行读取字段名。你知道吗示例:
相关问题 更多 >
编程相关推荐