从csv打印Python Matplotlib
我可以使用matplot从一个简单的csv进行绘图,如下所示:从csv打印Python Matplotlib,python,csv,matplotlib,plot,Python,Csv,Matplotlib,Plot,我可以使用matplot从一个简单的csv进行绘图,如下所示: 1 2 2 4 3 8 4 16 5 32 . . 这些值由制表符分隔。 现在我需要从csv读取数据,如下所示: # Name Test Number1 \\Name of the csv #Sometimes there is a comment which has one line # or even more Catego
1 2
2 4
3 8
4 16
5 32
.
.
这些值由制表符分隔。
现在我需要从csv读取数据,如下所示:
# Name Test Number1 \\Name of the csv
#Sometimes there is a comment which has one line
# or even more
Category1 Number2 Test Temperature Voltage \\Labels for the plot
# [1] [1/min] [s] [°C] [mV] \\Units
MinMax 2.3 5 9 48 22 \\Data starts here
MinMax 9.87 6.01 8 9 3
MinMax 1 2 3 4 5
MinMax 99.52 5 8 6.66 0
如何从我的csv和绘图标签中获取数据?例如,如果我想绘制测试和温度?有大量的行和列
谢谢大家!
import csv
with open('path\to\sample.txt', 'r') as csvfile:
csvreader = csv.reader(csvfile, delimiter='\t')
foundheader=False
for row in csvreader:
if row[0].startswith(' '):
foundheader=True
if foundheader:
print row
用于测试的样本数据
#Name Test Number1
#Sometimes there is a comment which has one line
#or even more
# Name Test Number1 \\Name of the csv
#Sometimes there is a comment which has one line
# or even more
Category1 Number2 Test Temperature Voltage
#[1] [1/min] [s] [°C] [mV]
MinMax 2.3 5 9 48 22
MinMax 9.87 6.01 8 9 3
MinMax 1 2 3 4 5
MinMax 99.52 5 8 6.66 0
输出
[' Category1', 'Number2', 'Test', 'Temperature', 'Voltage', '']
[' #[1]', '[1/min]', '[s]', '[\xc2\xb0C]', '[mV]', '']
[' MinMax', '2.3', '5', '9', '48', '22', '']
[' MinMax', '9.87', '6.01', '8', '9', '3']
[' MinMax', '1', '2', '3', '4', '5']
[' MinMax', '99.52', '5', '8', '6.66', '0']
重复的谢谢你的链接,不知为什么我没有找到这个。这个线程的问题是,标题正好有10行长。在我的csv中,我不知道需要跳过多少行。此外,我想得到与标签线。我不确定genfromtxt是否适合我的问题。如果您知道标题标签,请逐行读取数据并跳过所有行,直到您将行与标题匹配为止。我不知道标题标签。我只知道标题标签的行以空白开头。如何搜索每一行,直到找到以空白开头的行?空白不是一个理想的值,我看到在您的数据中,第一行以空格“#Name Test Number1”开头谢谢Shijo!不幸的是,我不能提高投票率,因为我没有足够的声誉。