简体   繁体   English

如何从文件读取不同的度量并保存?

[英]How to read different measures from files into and save?

I have few csv files that all of the has the following information: 我的csv文件很少,所有文件都包含以下信息:

在此处输入图片说明

I need to take each row from every CSV files and add as a row in each different Label separately to be able to take the mean of all measures among all CSV files. 我需要从每个CSV文件中获取每一行,并分别在每个不同的Label中添加为一行,以便能够对所有CSV文件中的所有度量取平均值。 I wrote the following lines, but I do not know how to write in an efficient and clean way. 我写了以下几行,但我不知道如何以有效和简洁的方式编写。 defining 6 different numpy arrays and then adding each row of csv to them separately does not seem a smart way of writing code. 定义6个不同的numpy数组,然后将csv每一行分别添加到它们中,这似乎不是编写代码的明智方法。 what do you suggest? 你有什么建议? Thanks 谢谢

for filename in csv_files:
     print 'reading CSV file '+ filename
     file_path=join(csv_dir, filename)
     csv = np.genfromtxt (file_path, delimiter=",")

As in the comment: Read each file into a numpy.ndarray and store them into a list. 如注释中所示:将每个文件读入numpy.ndarray并将它们存储在列表中。 Afterwards stack them together, eg with np.hstack(arraylist). 然后将它们堆叠在一起,例如,使用np.hstack(arraylist)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM