python小练习之航空公司数据练习题(二)
2020-06-28 11:50:51 来源:易采站长站 作者:易采站长站整理
flights.drop_duplicates() #重复值处理
print("n4.统计缺失值") #缺失值统计查看
nulls = np.sum(flights.isnull())
nullcols = nulls.loc[(nulls != 0)]print(nullcols)
print("这里有",len(nullcols),"个变量存在缺失值")
1.查看数据规模
(336776, 19)
----------------------------------------2.查看变量名
Index(['year', 'month', 'day', 'dep_time', 'sched_dep_time', 'dep_delay',
'arr_time', 'sched_arr_time', 'arr_delay', 'carrier', 'flight',
'tailnum', 'origin', 'dest', 'air_time', 'distance', 'hour', 'minute',
'time_hour'],
dtype='object')
----------------------------------------
3.查看数据基本信息
RangeIndex: 336776 entries, 0 to 336775
Data columns (total 19 columns):
year 336776 non-null int64
month 336776 non-null int64
day 336776 non-null int64
dep_time 328521 non-null float64
sched_dep_time 336776 non-null int64
dep_delay 328521 non-null float64
arr_time 328063 non-null float64
sched_arr_time 336776 non-null int64
arr_delay 327346 non-null float64
carrier 336776 non-null object
flight 336776 non-null int64
tailnum 334264 non-null object
origin 336776 non-null object
dest 336776 non-null object
air_time 327346 non-null float64
distance 336776 non-null float64
hour 336776 non-null float64
minute 336776 non-null float64
time_hour 336776 non-null object
dtypes: float64(8), int64(6), object(5)
memory usage: 48.8+ MB
----------------------------------------
4.统计缺失值
dep_time 8255
dep_delay 8255
arr_time 8713
arr_delay 9430
tailnum 2512
air_time 9430
dtype: int64
这里有 6 个变量存在缺失值
这里需要注意的是缺失值,这意味着我们在后面进行匹配是有必要考虑缺失情况进行补充。
问题1a
寻找达到延误2小时或者更多的航班
"""
要求:到达延误2小时或更多的航班
思路:寻找arr_delay大于120的航班,或者到达时间比预计达到时间多120分钟以上的航班(因为有航班延误数据缺失)
"""
arr2 = flights[flights['arr_delay'] >= 120] #选择延误arr_delay指标大于2小时的
arr2_na = flights[(flights['arr_delay'].isnull())] #指定arr_delay指标为空的数据,在其中进行寻找
arr2_na = arr2_na[arr2_na['arr_time']-arr2_na['sched_arr_time'] >= 200] #通过到达时间减去预计到达时间来判断是否延误两小时以上
#########################
#注意:













闽公网安备 35020302000061号