http://ym6se2.natappfree.cc
import requests
import pandas as pd
import time
import csv
def dsf(vb):
url = 'http://127.0.0.1:5000/index/as/'+vb
re = requests.get(url)
df = pd.read_json(re.text,encoding="utf-8", orient='records')
df.columns = ['0', '1', '2', '3', '4',"5","6","7","8","9"]
singlelist = []
for i in range(0,10):
singlelist.append(list(df[str(i)]))
df1 = pd.DataFrame(singlelist,columns=['a','b', 'c', 'd','e','f','g'])
df1.to_csv('SPTCC-20150401.csv', mode='a', header=False, index=None)
print("ok")
time.sleep(0.5)
for x in range(100):
dsf(str(x))
http://53pu93.natappfree.cc
这是运行程序结果
import numpy as np
import pandas as pd
from jinja2 import Markup
from pyecharts.charts import Bar
from pyecharts import options as opts
import streamlit as st
import streamlit.components.v1 as components
import time
import os
import plotly.express as px
import pandas as pd
from datetime import datetime
import os
#clear memory
import gc
#获取当前的时间
from collections import Counter
def fg(choose):
data = pd.read_csv(r'一卡通乘客刷卡数据1\SPTCC-'+choose+'.csv\SPTCC-'+choose+'.csv',encoding='gbk', header=None, names=['a','b','c','d',"e","f","g"])
df = data[(data["e"] == "地铁")]
#print(df1)
v = Counter(list(df["d"]))
t = 0
linyuyu = ["1号","2号","3号","4号","5号","6号","7号","8号","9号","10号","11号","12号","13号","14号","15号","16号","17号","18号","19号"]
linyuyu1 = []
for xx in linyuyu:
for x in list(v):
if xx in x and '1'+xx not in x:
#print(x+" "+str(dict(v)[x]))
t = t+int(dict(v)[x])
linyuyu1.append(t)
columns = linyuyu[0:16]
data1 = linyuyu1
bar = (
Bar()
.add_xaxis(columns)
.add_yaxis("号线", data1, stack = "stack1") # y轴设置
.reversal_axis()
.set_global_opts(title_opts=opts.TitleOpts(title="流量"))
.set_series_opts(label_opts=opts.LabelOpts(is_show=False,position="right"))
)
c = bar.render_embed()
components.html(c,height=700)
hk = st.selectbox("",linyuyu[0:16])
listtt = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24']
listttt = []
for iey in listtt:
df3=df[df['d'].str.contains(hk)]
df3 = df3[~ df3['d'].str.contains('1'+hk)]
df1=df3[df3['c'].str.contains(iey+':')]
df1 = df1[~ df1['c'].str.contains(':'+iey+':')]
listttt.append(len(df1))
bar2 = (
Bar()
.add_xaxis(listtt)
.add_yaxis(hk, listttt, stack = "stack1") # y轴设置
.reversal_axis()
.set_global_opts(title_opts=opts.TitleOpts(title="流量"))
.set_series_opts(label_opts=opts.LabelOpts(is_show=False,position="right"))
)
c1 = bar2.render_embed()
components.html(c1,height=500)
def file_name(file_dir):
asd = []
for files in os.walk(file_dir):
if “csv” in files[0]:
asd.append(files[0])
kkk= 0
for x in asd:
asd[kkk]=x.replace(“一卡通乘客刷卡数据1”,"")[7:].replace(".csv","")
kkk = kkk+1
return asd #当前路径下所有非目录子文件
vv= file_name(r"一卡通乘客刷卡数据1")
print(vv)
def GetNowTime():
return time.strftime("%Y-%m-%d %H:%M",time.localtime(time.time()))
st.write(“当前时间为”,GetNowTime())
st.sidebar.header(“demo”)
choose = st.sidebar.selectbox("",vv)
fg(choose)