%%time
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Line, Timeline
from pyecharts.globals import ThemeType
import pandas as pd
import numpy as np
from datetime import datetime
import warnings
warnings.filterwarnings("ignore")
from pyecharts.charts import Line
from pyecharts.charts import Bar, Timeline, Map, Pie, Line
from pyecharts.commons.utils import JsCode
import math
data = pd.read_excel('N185_数据源.xlsx',usecols=["交易时间","交易账号","收付标志","交易对手账卡号","交易金额","交易余额"])
data['日期'] = data['交易时间'].apply(lambda x:datetime.strftime(x,"%Y-%m-%d %H:%M:%S"))
data.loc[((data['收付标志']== "进")&(data['交易金额']>0)),"收"]=data['交易金额'].apply(lambda x:int(x/10000))
data.loc[((data['收付标志']== "出")&(data['交易金额']>0)),"支"]=data['交易金额'].apply(lambda x:int(x/10000))
data['交易余额'] = data['交易余额'].apply(lambda x:int(x/10000))
data.fillna("-",inplace=True)
data2 = data.loc[~(((data['收']=="-")&(data['支']=="-"))|((data['收']=="-")&(data['支']==0))|((data['收']==0)&(data['支']=="-")))]
data2.to_excel("C://Users//wj//Desktop//linshi//总.xlsx")
def timeline_bar() -> Timeline:
ben_list = data2["交易账号"].unique()
tl = Timeline()
for i in ben_list:
df2=data2[(data2["交易账号"]==i)*(data2["交易金额"]>= 2)]
if df2.empty:
break
x_data = df2['日期'].to_list()
y_total = df2['交易余额'].to_list()
y_in = df2['收'].to_list()
y_out = df2['支'].to_list()
bar = (
Bar()
.add_xaxis(x_data)
.add_yaxis(
series_name="",
y_axis=y_total,
stack="总量",
itemstyle_opts=opts.ItemStyleOpts(color="rgba(0,0,0,0)"),
)
.add_yaxis(series_name="上升", y_axis=y_in, stack="总量")
.add_yaxis(series_name="下降", y_axis=y_out, stack="总量")
.set_global_opts(yaxis_opts=opts.AxisOpts(type_="value"),
datazoom_opts=opts.DataZoomOpts(range_start=1,range_end=7))
)
tl.add(bar, "本:{}".format(i))
tl.add_schema(play_interval=3000,
is_timeline_show=True,
is_auto_play=False)
return tl
timeline_bar().render("N185_按时间轴轮播 涨跌图 分析收支.html")
CPU times: total: 547 ms
Wall time: 605 ms
'D:\\myjupyter\\自制python 脚本工具库\\N185_按时间轴轮播 涨跌图 分析收支.html'