import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")
Setup Complete
我们使用pd.read_csv
来读取档案
# Path of the file to read
flight_filepath = "./flight_delays.csv"
# Read the file into a variable flight_data
flight_data = pd.read_csv(flight_filepath, index_col="Month")
因为month这个column并不是日期的格式,因此在读取的时候,不用加上parse_dates=True
因为资料集很小,可以只用一行就印出全部的资料
# Print the data
flight_data
将Airline code NK的班机做成bar chart
# Set the width and height of the figure
plt.figure(figsize=(10,6))
# Add title
plt.title("Average Arrival Delay for Spirit Airlines Flights, by Month")
# Bar chart showing average arrival delay for Spirit Airlines Flights by month
sns.barplot(x=flight_data.index, y=flight_data['NK'])
# Add label for vertical axis
plt.ylabel("Arrival delay (minutes)")
Text(0, 0.5, 'Arrival delay (minutes)')
在bar chart中,有几个主要的components
sns.barplot
- 告诉Notebook要创造一个bar chartx=flight_data.index
- 选择index当作x轴的资料y=flight_data['NK']
- 要用什麽资料来当作bar chart的高度flight_data['month']
下方的程序码是将flight_data
的资料做成heatmap
# Set the width and height of the figure
plt.figure(figsize=(14,7))
# Add title
plt.title("Average Arrival Delay for Each Airline, by Month")
# Heatmap showing average arrival delay for each airline by month
sns.heatmap(data=flight_data, annot=True)
# Add label for horizontal axis
plt.xlabel("Airline")
Text(0.5, 42.0, 'Airline')
heatmap也包含三个组件
sns.heatmap
- 告诉notebook要创建heatmapdata=flight_data
- 告诉heatmap要使用甚麽资料annot=True
- 将值显示在heatmap中,若没有使用的话,只看的到颜色,看不到数值
<<: Day19 - 写出更有品质的程序码,信 eslint 得永生
>>: Day 19 : 笔记篇 06 — 结合资讯处理流程,让笔记的 Metadata 变得更详细
前言 昨天我们算是把api service完成了 那我们今天来写一些简单的前端 以及使用balde的...
正文 今天要来开机器,先去下载server版的Ubuntu 20.04 iso,因为以前自己做环境练...
做完了这几天的JAVA分享。。。我说是分享啦,因为我没有厉害到可以教别人 恩,所以做完分享之後,我也...
前面四篇讲的 slice 基础都是当天看当天吸收,消化过後出在铁人赛的文章上。这样安排非常紧凑的,但...
leetcode可以说是工程师的试炼场,收集了许多公司的面试考题,可说是题海无涯,那麽就开始刷题之...