加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
traffice.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
Obloquy_Caveat_95f8 提交于 2020-07-29 19:52 . first
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://root:123@localhost/baidutraffice')
df = pd.read_sql('select * from journeys', engine)
df1 = df[((df['journey_number'] == df['journey_number'].shift(1))
& (df['route_number'] == df['route_number'].shift(1)))
| ((df['journey_number'] == df['journey_number'].shift(-1)) &
(df['route_number'] == df['route_number'].shift(-1)))]
df2 = df[((df['route_number'] != df['route_number'].shift(1))
& (df['route_number'] != df['route_number'].shift(-1)))
]
df3 = df1[df1['route_number'] == df1['route_number'].shift(-1)]
df3['The_duration'] = df1[df1['route_number'].shift(-1) == df1['route_number']].loc['The_duration'] = df1['The_duration'] + df1['The_duration'].shift(-1)
df3['vehicle_name'] = df1[df1['route_number'].shift(-1) == df1['route_number']].loc['vehicle_name'] = df1[
'vehicle_name'] + ',' + df1['vehicle_name'].shift( -1)
df3['arrive_station_name'] = df1[df1['route_number'].shift(-1) == df1['route_number']].loc['arrive_station_name'] = df1[
'arrive_station_name'].shift(-1)
df3['arrive_time'] = df1[df1['route_number'].shift(-1) == df1['route_number']].loc['arrive_time'] = df1[
'arrive_time'].shift(-1)
DF = pd.concat([df2, df3])
DF.to_sql(name='journeys_modify', con=engine, if_exists='replace', index=False)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化