根据我的计算,我的应用程序生成数量可变且名称不同的数据框列。
我正在尝试绘制这些图,但正在努力弄清楚如何将列名作为变量传递到 pyplot 中,但缺少明显的内容。
如果我指定单独的列名称,效果很好,但如何将其作为变量传递?
ax.plot( df.dti, df['ma_11'] ) # Works but next time it could be ma_12
str='ma_12'
ax.plot( df.dti, df[str?????] ) # How to pass str into the plot function?
提前致谢。
最佳答案
如果你知道你有一个范围,你可以使用这个:
for in range(min_ma, max_ma + 1):
ax.plot(df.dti, df['ma_{}'.format(i)])
关于python - 如何将 pd 列或系列作为变量传递到 plt.plot 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55161260/