import pandas as pd
import matplotlib.pyplot as plt
> importing csv files
january = pd.read_csv('divident_month/january.csv')
april = pd.read_csv('divident_month/april.csv')
july = pd.read_csv('divident_month/july.csv')
october = pd.read_csv('divident_month/october.csv')
> substracting column 'Open' to column close
jangain = january['Open']-january['Close']
aprgain = april['Open']-april['Close']
julgain = july['Open']-july['Close']
octgain = october['Open']-october['Close']
>plotting
medium=[jangain, aprgain, julgain, octgain]
plt.plot(medium)
plt.show()
## jan = plt.plot(jangain, label='january')
## apr =plt.plot(aprgain, label='april')
## jul =plt.plot(julgain, label='july')
## oct =plt.plot(octgain, label='october')
## plt.legend()
如何将多个项目绘制成一个图表,而不重复我在##中的操作。 我有多个不同月份重复代码的文件(它们在不同的文件中分组,分别对应于分区前月份、分区月和分区后月份)
我已经尝试将它们分组到一个列表中(中间),并将列表传递到plt.plot(medium)
但这似乎不起作用
我还提供了图的名称(例如1月、4月…),因为我将它们导入到一个不同的文件中,用于q1、q2、q3、q4分析(以防信息混淆)
顺便说一句,这是我试图用python做财务工作
您可以这样做:
相关问题 更多 >
编程相关推荐