从以往的时间序列值,进行指数平滑,做两次预测出下一个时间的估计值。
目录结构如下:
forecast.py
# -*-coding:utf-8 -*-
# Time:2015.11.25 sangjin
__author__ = 'hunterhug'
import matplotlib
#matplotlib.use("Agg")
#matplotlib.use("TkAgg")
#matplotlib.use("gtk")
import matplotlib.pyplot as plt
from matplotlib.pyplot import savefig
from matplotlib.font_manager import FontProperties
from operator import itemgetter
#读取execel使用(支持07)
from openpyxl import Workbook
#写入excel使用(支持07)
from openpyxl import load_workbook
import os
def judgefile():
path = input("请输入该目录下的excel文件名:") # file path
if os.path.isfile(path):
return path.lower()
else:
print("文件不存在")
return judgefile()
def writeexcel07(path, content, name='Sheet1', sheetnum=0):
wb=Workbook()
#sheet=wb.add_sheet("xlwt3数据测试表")
sheet=wb.create_sheet(sheetnum,name)
# values = [["名称", "Hadoop编程实战", "hbase编程实战", "lucene编程实战"], ["价格", "52.3", "45", "36"], ["出版社", "机械工业出版社", "人民邮电出版社", "华夏人民出版社"], ["中文版式", "中", "英", "英"]]
for i in range(0,len(content)):
for j in range(0,len(content[i])):
sheet.cell(row = i+1,column= j+1).value = content[i][j]
# sheet.cell(row = 1,column= 2).value="温度"
wb.save(path)
print("写入数据成功!")
def read07excel(path):
excelcontent = []
wb2=load_workbook(path)
sheetnames = wb2.get_sheet_names()
ws=wb2.get_sheet_by_name(sheetnames[0])
row=ws.get_highest_row()
col=ws.get_highest_col