spyder python3.7怎么用_如何使用Python3.7(Spyder)计算数据读数的移动平均值?

这段代码展示了如何创建一个简单的销售图表,并试图计算和绘制移动平均线(MA)和居中移动平均线(CMA),但遇到了问题。提供的Python代码导入了matplotlib库来展示数据,定义了一个函数`make_chart_simple_line_chart`,该函数使用给定的销售数据和时间周期绘制图表,包括销售数量。然而,实际的MA和CMA计算及存储并未在代码中完成。
摘要由CSDN通过智能技术生成

我已经能算出销售额了。

现在我需要绘制移动平均线和居中移动平均线,并存储这些值以供进一步分析。下面是我能做的。

我试过取平均值,但无法计算MA和CMA并存储它。

import matplotlib.pyplot as plt

from collections import Counter

def make_chart_simple_line_chart(plt):

period = ['201601', '201602', 201603, 201604, 201605, 201606, 201607, 201608, 201609, 201610, 201611, 201612, 201701, 201702, 201703, 201704, 201705, 201706, 201707, 201708, 201709, 201710, 201711, 201712, 201801, 201802, 201803, 201804, 201805, 201806, 201807, 201808, 201809, 201810, 201811, 201812]

sale = [9478, 9594, 14068, 9692, 9718, 14144, 9294, 10072, 14254, 10508, 11224, 17640, 11300, 11656, 17360, 11342, 12300, 17334, 11296, 12452, 16886, 11878, 13482, 19260, 13932, 13600, 20122, 13134, 14564, 19354, 13104, 13562, 17350, 12486, 12570, 17716]

# create a line chart, period on x-axis, sale on y-axis

plt.plot(period, sale, color='green', marker='o', linestyle='solid')

# add a title

plt.title("Sales Chart")

# add a label to the y-axis

plt.ylabel("number of contracts sold")

plt.show()

if __name__ == "__main__":

make_chart_simple_line_chart(plt)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值