我正在编写一个脚本,它为两个单独的项目提供了一个pandas数据框,并为每个项目绘制了时间序列数据。
所以我的日期框架df看起来像这样
V: a-1 V: a-2 V: a-3 V: b-1 V: b-2 V: b-3
TimeDT:
2018-02-11 22:00:00 1 3 5 7 4 3
2018-02-11 22:05:00 2 3 6 5 5 4
...
当我把它写成函数时,
def generate_voltage_plot(file_path, length, arg1, arg2):
plt.figure()
for i in range(length):
plt.plot( arg1, '-', color=myColors['cool'][i])
for i in range(length):
plt.plot( arg2, '-', color=myColors['warm'][i])
plt.title('V [V]')
plt.ylabel('V [V]')
plt.savefig(file_path)
generate_voltage_plot('Vplot.png', 3, df['V: a-' + str(i + 1)], df['V: b-' + str(i + 1)]
我收到此错误。
File "pandas\_libs\index.pyx", line 117, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 139, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1265, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1273, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'V: a-6'
我不明白它为什么循环过去3.当我运行它而不是作为一个函数时,它不会发生。感谢您提供任何指导或更好的方法。