Skip to content

Commit 3b43398

Browse files
committed
Submit File
0 parents  commit 3b43398

File tree

10 files changed

+2898
-0
lines changed

10 files changed

+2898
-0
lines changed

.ipynb_checkpoints/Flight-checkpoint.ipynb

Lines changed: 1074 additions & 0 deletions
Large diffs are not rendered by default.

30.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import plotly.plotly as py
2+
import plotly.graph_objs as go
3+
import pandas as pd
4+
5+
df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
6+
df_airports.head() #读取机场数据
7+
8+
df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
9+
df_flight_paths.head() #读取航班数据
10+
11+
12+
13+
trace0 = go.Scattergeo( #线的颜色
14+
locationmode = 'USA-states',
15+
lon = df_airports['long'],
16+
lat = df_airports['lat'],
17+
hoverinfo = 'text',
18+
text = df_airports['airport'],
19+
mode = 'lines',
20+
marker = dict(
21+
size=2,
22+
color='rgb(255, 0, 0)',
23+
line = dict(
24+
width=3,
25+
color='rgba(68, 68, 68, 0)'
26+
)
27+
)
28+
)
29+
30+
data = [trace0]
31+
32+
cluster0 = [] #每个机场的点
33+
for i in range( len( df_flight_paths ) ):
34+
cluster0 .append(
35+
dict(
36+
type = 'scattergeo',
37+
locationmode = 'USA-states',
38+
lon = [ df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i] ],
39+
lat = [ df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i] ],
40+
mode = 'lines',
41+
line = dict(
42+
width = 1,
43+
color = 'red',
44+
),
45+
opacity = float(df_flight_paths['cnt'][i])/float(df_flight_paths['cnt'].max()),
46+
)
47+
)
48+
49+
updatemenus = list([ #按钮
50+
dict(type="buttons",
51+
buttons=list([
52+
dict(label = 'None',
53+
method = 'update'),
54+
dict(label = 'Cluster 0',
55+
method = 'update',
56+
args = [{'annotations':cluster0}]),
57+
]),
58+
)
59+
])
60+
61+
layout = dict( title = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)', #布局
62+
showlegend = False,
63+
geo = dict(
64+
scope='north america',
65+
projection=dict( type='azimuthal equal area' ),
66+
showland = True,
67+
landcolor = 'rgb(243, 243, 243)',
68+
countrycolor = 'rgb(204, 204, 204)',
69+
),
70+
updatemenus=updatemenus
71+
)
72+
73+
fig = dict(data=data, layout=layout) #数据带入
74+
75+
py.plot(fig, filename='relayout_option') #实现

Flight.ipynb

Lines changed: 1074 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# python-requests_html-with-flightaware #
2+
3+
# 1.开发环境配置 #
4+
5+
6+
- 安装Python3.x+
7+
8+
- 下载本教程配套的压缩包
9+
10+
- 安装Anaconda套装,点击这个网址 [link](https://www.anaconda.com/download/)
11+
12+
- 打开套装里的终端 Anaconda Prompt
13+
14+
- 用终端cd命令进入压缩包解压的文件目录 如cd C:\Users\51774\Desktop\python-requests_html-with-flightaware
15+
16+
- 进入终端后执行代码如下
17+
18+
________________________________________
19+
>>> pip install requests_html
20+
>>> pip install pandas
21+
>>> pip install numpy
22+
>>> cd C:\Users\51774\Desktop\python-requests_html-with-flightaware
23+
>>> jupyter notebook
24+
25+
26+
# 2.爬取数据 #
27+
28+
29+
30+
31+
- 打开Flight.ipynb文件查看代码
32+
33+
- Shitf+Enter运行代码
34+
35+
36+
37+
38+
## Image:代码 ##
39+
![](https://i.imgur.com/ewPnTD4.png)
40+
_________________________________
41+
42+
## Image:制定的表格 ##
43+
44+
![](https://i.imgur.com/vix3MQA.png)
45+
___________________________________
46+
47+
## Image:生成的表格 ##
48+
![](https://i.imgur.com/29twv5J.png)
49+
___________________________________
50+
51+
52+
53+
54+
55+
# 3.可视化数据 #
56+
- 我们利用plotly可视化工具
57+
58+
- 需要注册账号,获得账户和密钥,点击这个网址 [link](https://plot.ly/accounts/login/?action=login#/)
59+
60+
- 打开cmd终端
61+
62+
- 在终端里调用plotly库
63+
64+
________________________________________
65+
>>> import plotly
66+
>>> plotly.tools.set_credentials_file(username='xxx',api_key= 'xxx')
67+
>>> #xxx是在plotly账户设置-API Keys里,Username,API Keys.
68+
69+
70+
- 打开编译器
71+
72+
- 用编译器运行30.py代码
73+
74+
## Image:运行提示 ##
75+
76+
![](https://i.imgur.com/g8vetaz.png)
77+
____________________________________
78+
79+
- 运行完后会自动弹出网页
80+
81+
- 网页里是可视化的机场数据
82+
83+
## Image:机场数据 ##
84+
![](https://i.imgur.com/T5SpoUN.png)
85+
86+
87+
88+
89+
90+
# 4.常见问题 #
91+
1. 爬取数据后导出的是.csv的文件不是存储到数据库?
92+
93+
> 由于Plotly可视化工具支持导入.csv表格文件,所以没有选择导入到数据据做可视化
94+
95+
2. 爬取的是什么航班数据?
96+
> 爬取的是重庆飞往拉萨的3U8633/CSC8633航班数据
97+
98+
3. 该航班数据有什么亮点?
99+
> 5月14日,川航3U8633重庆-拉萨航班,驾驶舱右座前风挡玻璃破裂脱落,机组实施紧急下降。机组正确处置,飞机于07:46分安全备降成都双流机场,所有乘客平安落地,有序下机。
100+
101+
4. 为什么选择该航班?
102+
> 做一个项目的同时,并不仅仅为人们提供工作,而是让我们整个国家感到自豪。
103+
104+
> 我想把这件事情传递下去,让人们铭记,3U8633机组拯救了几百位乘客。
105+
106+
> 致敬!

image/1.jpg

158 KB
Loading

image/2.jpg

20.4 KB
Loading

image/3.jpg

43.6 KB
Loading

image/4.jpg

10.7 KB
Loading

image/5.png

212 KB
Loading

0 commit comments

Comments
 (0)