zoukankan      html  css  js  c++  java
  • 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()

      

  • 相关阅读:
    CCS3.3安装常见问题(以合众达的为例)
    typedef unsigned long (__stdcall *THREADFUNC)(void *)
    Prism学习(8)模块间通讯
    Prism学习(6)Shell Region View
    Prism学习(4)弃远就近UnityBootstrapper
    Prism学习(2)初识Unity
    Prism学习(5)Hello Silverlight
    Prism学习(1)前期准备
    Prism学习(7)Commands
    Prism学习(9)阶段性总结
  • 原文地址:https://www.cnblogs.com/jiftle/p/7261116.html
Copyright © 2011-2022 走看看