[Profiles] say Python WEB application pyechart in the flask

Personal notes summarize, readability is not high. Only for their own use are summarized. Afraid to ever forget.
Here we used tushare, pandassuch as python components.

The case pyechart

    c = (
           Bar()
            .add_xaxis(["2020","2019","2018","2017","2016","2015","2014","2013","2012","2011","2010"])
            .add_yaxis("最高价", df2['high'].tolist())
            .add_yaxis("最低价", df2['low'].tolist())
            .add_yaxis("平均价", df2['mean'].tolist())
            .set_global_opts(title_opts=opts.TitleOpts(title=stock_code))
    )
    return c

Get_price defined function

def get_price(stock_code):
    stock_price = ts.get_hist_data(stock_code, ktype='M')
    stock_price.to_csv('stock_price.csv')
    price_online = pd.read_csv('stock_price.csv', dtype={'code': np.str})
    price_online_bf =price_online.loc[(price_online['open'] != 0),['date','open','high','close','low']]
    price_online_bf.to_csv('stock_price_online.csv')
    df = pd.read_csv('stock_price_online.csv')
#    print(df.head(2))
    df['date'] = pd.to_datetime(df['date'])
    df = df.set_index('date') # 将date设置为index
    date_array=('2020','2019','2018','2017','2016','2015','2014','2013','2012','2011','2010')
    date_list=['2020','2019','2018','2017','2016','2015','2014','2013','2012','2011','2010']
    min_array_list=[]
    max_array_list=[]
    mean_array_list=[]
    for each in date_array:
#        print(df[each])
        price_min=df[each].low.min()
        min_array_list.append(price_min)
#        print(price_min)
        price_max=df[each].high.max()
#        print(price_max)
        max_array_list.append(price_max)
        price_mean=df[each].close.mean()
#        print(round(price_mean,2))
        mean_array_list.append(round(price_mean,2))
#        print(min_array_list)
    own_dataframe={'date':date_list,'high':max_array_list,'low':min_array_list,'mean':mean_array_list}
    df2=pd.DataFrame(own_dataframe)

    c = (
           Bar()
            .add_xaxis(["2020","2019","2018","2017","2016","2015","2014","2013","2012","2011","2010"])
            .add_yaxis("最高价", df2['high'].tolist())
            .add_yaxis("最低价", df2['low'].tolist())
            .add_yaxis("平均价", df2['mean'].tolist())
            .set_global_opts(title_opts=opts.TitleOpts(title=stock_code))
    )
    return c

flask of view function call

@main.route('/stock/<stock_code>')
def stocklist20(stock_code):
    c = get_price(stock_code)
    return Markup(c.render_embed())

run:

flask run -h '0.0.0.0' -p 9000

By calling Address: http://172.30.200.252:9000/stock/600104, get the following data

Display effects:

Guess you like

Origin www.cnblogs.com/zhangshengdong/p/12573395.html