我在这样的文本文件中有一堆数据:
99150, 2012-05-18 14:30:08.592276
100350, 2012-05-18 14:31:09.093357
97710, 2012-05-18 14:32:09.583485
94980, 2012-05-18 14:33:10.047794
95670, 2012-05-18 14:34:10.559798
97170, 2012-05-18 14:35:11.073576
98850, 2012-05-18 14:36:11.562930
98280, 2012-05-18 14:37:12.058591
97950, 2012-05-18 14:38:12.547585
102510, 2012-05-18 14:39:13.053431
我想对其进行简单的绘图并输出图像。我从以下开始:
#!/bin/python
import csv
import matplotlib.pyplot as plt
import numpy as np
filename="pps_counter.log"
def getColumn(filename, column):
results = csv.reader(open(filename), delimiter=",")
return [result[column] for result in results]
time = getColumn(filename,1)
packets = getColumn(filename,0)
plt.figure("Packets Per Minute")
plt.xlabel("Time(minutes)")
plt.ylabel("Number of Packets")
plt.plot(time,packets)
当我运行它时,我收到以下错误:
Traceback (most recent call last):
File "plotter.py", line 16, in <module>
time = getColumn(filename,1)
File "plotter.py", line 14, in getColumn
return [result[column] for result in results]
IndexError: list index out of range
任何人都可以帮忙吗?