我需要绘制2000年至2019年每个月的股票交易量的月总和。现在,我有以下代码:
yearList = [j for j in range(2001,2020)]
yearsplits= np.searchsorted(years, yearList)
volumeYears=np.searchsorted(sp_volume, yearsplits)
for j in range(19):
print(" {}: {:12.0f}".format(j+2000, volumeYears[j].sum()))
months = dates.astype('datetime64[M]').astype(int) # this is a sequence increasing by 1 every month
months -= months[0] #to skip the months before 1/1/2000
monthsplits = np.searchsorted(months, range(1, 19*12+2))
# from 1/1/2000 to 12/31/2018 are 19years * 12months, and Jan,Feb 2019 at the end
volumeMonths=np.searchsorted(sp_volume, monthsplits)
for j in range(19):
print(" {}: {:12.0f}".format(j+2000, volumeMonths[j].sum()))
但是volumeMonths
和volumeYears
返回全零,这导致volumeMonths.sum()
和volumeYears.sum()
也返回零。如何获得每个月的实际数量总和?