import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sn
data=pd.read_csv('../data/air_data.csv') explore=data.describe(percentiles=[],include='all').T
from datetime import datetime ffp=data['FFP_DATE'].apply(lambda x:datetime.strptime(x,'%Y/%m/%d')) ffp_year=ffp.map(lambda x : x.year) #绘制各年份会员入会人数直方图 fig=plt.figure(figsize=(8,5)) plt.rcParams['font.sans-serif'] = 'SimHei' # 设置中文显示 plt.rcParams['axes.unicode_minus'] = False plt.hist(ffp_year, bins='auto', color='#111111') plt.xlabel('年份') plt.ylabel('入会人数') plt.title('各年份会员入会人数 2020310143049吕莹') plt.show() plt.close
male=pd.value_counts(data['GENDER'])['男'] female=pd.value_counts(data['GENDER'])['女'] fig = plt.figure(figsize = (7 ,4)) # 设置画布大小 plt.pie([ male, female], labels=['男','女'], colors=['lightskyblue', 'lightcoral'], autopct='%1.1f%%') plt.title('会员性别比例 2020310143049吕莹') plt.show() plt.close
# 提取属性并合并为新数据集 data_corr = data[['FFP_TIER','FLIGHT_COUNT','LAST_TO_END', 'SEG_KM_SUM','EXCHANGE_COUNT','Points_Sum']] age1 = data['AGE'].fillna(0) data_corr['AGE'] = age1.astype('int64') data_corr['ffp_year'] = ffp_year # 计算相关性矩阵 dt_corr = data_corr.corr(method = 'pearson') print('相关性矩阵为:\n',dt_corr) # 绘制热力图 import seaborn as sns plt.subplots(figsize=(10, 10)) # 设置画面大小 sns.heatmap(dt_corr, annot=True, vmax=1, square=True, cmap='Blues') plt.title('热力图-2020310143049吕莹') plt.show() plt.close
# 去除票价为空的记录 airline_notnull = data.loc[data['SUM_YR_1'].notnull() & data['SUM_YR_2'].notnull(),:] print('删除缺失记录后数据的形状为:',airline_notnull.shape) # 只保留票价非零的,或者平均折扣率不为0且总飞行公里数大于0的记录。 index1 = airline_notnull['SUM_YR_1'] != 0 index2 = airline_notnull['SUM_YR_2'] != 0 index3 = (airline_notnull['SEG_KM_SUM']> 0) & (airline_notnull['avg_discount'] != 0) index4 = airline_notnull['AGE'] > 100 # 去除年龄大于100的记录 airline = airline_notnull[(index1 | index2) & index3 & ~index4] print('数据清洗后数据的形状为:',airline.shape) import pandas as pd import numpy as np
标签:plt,会员,airline,corr,notnull,import,data From: https://www.cnblogs.com/cyszd/p/17208831.html