python统计订单走势
#coding=utf-8 import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.ticker as ticker # ------------ 设置为系统中的中文字体------------ from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] # linux下中文乱码处理 mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # windows下中文乱码处理 # plot 线形图 # bar 条形图 # scatter 点状图 # stackplot 堆叠图 CONST_FIGURE_TYPE = 'plot' def read_csv(): filename = "E:/work/work_git/python_personalrepo/data/order_statis_2.csv" # filename = 'e:\\order_statis_2.csv' df = pd.read_csv(filename) # print df.head() return df # 格式化日期 def format_date(x, pos=None): thisindex = np.clip(int(x + 0.5), 0, len(df) - 1) datetime_ret = df['days'][thisindex] return datetime_ret # 构建数据 def build_data_ordercount(): x_axis_values = [] y_axis_values = [] # print df['days'] for index, row in df.iterrows(): x_axis_values.append(index) y_axis_values.append(row['count']) x_axis_values = np.arange(len(df)) # print x_axis_values # print y_axis_values fig,ax = plt.subplots() ax.plot(x_axis_values, y_axis_values, 'o-',label=u'订单数量') # x轴标签 倾斜角度 # plt.xticks(rotation=30) ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date)) fig.autofmt_xdate() return False # 构建数据 def build_data_ordermoney(): x_axis_values1 = [] y_axis_values1 = [] for index, row in df.iterrows(): x_axis_values1.append(index + 1) y_axis_values1.append(row['money']/1000.0) # print x_axis_values1 # print y_axis_values1 plt.plot( # X 轴 x_axis_values1, # y轴 y_axis_values1, 'ro-', label=u'订单金额') return False # 绘制图形 def show_figure(): plt.ylabel(u'订单数量') plt.xlabel(u'下单日期') plt.title(u'订单走势') plt.legend() plt.show() return False if __name__ == "__main__": df = read_csv() # print df.head() build_data_ordercount() build_data_ordermoney() show_figure()
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析