1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- """
- @author: luojunhui
- """
- from pyecharts import options as opts
- from pyecharts.charts import Line, Page
- from pyecharts.globals import ThemeType
- import pandas as pd
- file_path = '/Users/luojunhui/Downloads/0708-ana数据.xlsx'
- df = pd.read_excel(file_path, sheet_name='Sheet1')
- df['日期'] = pd.to_datetime(df['日期']).dt.strftime('%Y-%m-%d')
- df['账号来源'] = df.apply(lambda row: "{}-{}".format(row['模式类型'].replace('\n', ''), row['账号来源']), axis=1)
- print(df['账号来源'])
- pivot_df = df.pivot(index='日期', columns='账号来源', values='小程序第一层人数/阅读量')
- line = Line(init_opts=opts.InitOpts(theme=ThemeType.LIGHT, width="100%", height="600px"))
- line.add_xaxis(pivot_df.index.tolist())
- for product in pivot_df.columns:
- line.add_yaxis(
- product,
- pivot_df[product].tolist(),
- is_smooth=True,
- linestyle_opts=opts.LineStyleOpts(width=3),
- markline_opts=opts.MarkLineOpts(
- data=[
- opts.MarkLineItem(x="2024-07-02", name="分割")
- ],
- label_opts=opts.LabelOpts(position="insideEndTop"),
- linestyle_opts=opts.LineStyleOpts(width=2, color="grey")
- )
- )
- line.set_global_opts(
- title_opts=opts.TitleOpts(title="小程序打开率趋势", pos_left='center'),
- xaxis_opts=opts.AxisOpts(type_="category"),
- yaxis_opts=opts.AxisOpts(type_="value"),
- tooltip_opts=opts.TooltipOpts(trigger="axis"),
-
- legend_opts=opts.LegendOpts(
- pos_bottom='0%',
- pos_left='center',
- orient='horizontal',
- textstyle_opts=opts.TextStyleOpts(font_size=12),
- selected_mode='single',
- )
- )
- line.render("product_trends.html")
- print("Charts are rendered in 'product_trends.html'")
|