新闻中心
共享单车数据分析及可视化(共享单车调查报告数据分析总结怎么写)
目录
1.提出问题
2.理解数据
2.1采集数据
2.2导入数据
2.3查看数据信息
3.数据清洗
3.1缺失数据处理
3.2异常数据处理
3.3数据类型转换
4.构建模型
5.数据可视化
6.结论
1.提出问题
自行车共享系统是一种租赁自行车的方式,在这里,获得会员资格、租赁和自行车返回的过程是通过城市各处的自助服务站网络自动完成的。使用这些系统,人们可以从一个地方租一辆自行车,并在需要的基础上把它送回不同的地方。目前,世界上有超过500个自行车共享项目。 这些系统生成的数据使它们对研究人员很有吸引力,因为旅行时间、出发地点、到达地点和时间流逝都被显式地记录下来。可结合历史使用模式和天气数据,以预测自行车租赁需求。
2.理解数据
理解数据分为三部分:
1)采集数据:这一部分,根据研究问题,采集数据
2)导入数据:你要分析的数据可能在excel文件,或者数据库中,首先,你需要将数据导入到Python中的数据结构中。
3)查看数据集信息2.1采集数据
2.2导入数据
#导入处理数据包 import numpy as num import pandas as pd #导入绘图包 from matplotlib import pyplot as plt from matplotlib import pylab as plb import seaborn as sns #训练数据集 train=pd.read_csv("./train.csv") #测试数据集 test=pd.read_csv("./test.csv") print(训练数据集:,train.shape,测试数据集,test.shape) 训练数据集: (10886, 12) 测试数据集 (6493, 9)将两个文件合并为full方便进行下一步数据清洗。
#合并数据集,进行数据清洗 full=train.append(test,ignore_index=True) print(full:,full.shape) full: (17379, 12)2.3查看数据信息
head()查看数据内容,包含了atemp casual count datetime holiday humidity registered season temp weather windspeed workingday tji
datetime - 日期+时间
season - 1 = spring, 2 = summer, 3 = fall, 4 = winter
holiday - 节假日
workingday - 工作日
weather - 天气 1:晴朗,少云,多云,多云。
2:雾+云,雾+碎云,雾+少许云,雾
3:小雪,小雨+雷雨+散云,小雨+散云。
4:大雨+冰托盘+雷雨+雾,雪+雾
temp - 摄氏温度
atemp—体感温度
humidity -相对湿度
windspeed—风速
casual -发起的非注册用户租赁数量
registered-已注册用户租赁的数量
count -总租车人数 describe()、info()查看数据描述信息。full.describe() atemp casual count holiday humidity registered season temp weather windspeed workingday count 17379.000000 10886.000000 10886.000000 17379.000000 17379.000000 10886.000000 17379.000000 17379.000000 17379.000000 17379.000000 17379.000000 mean 23.788755 36.021955 191.574132 0.028770 62.722884 155.552177 2.501640 20.376474 1.425283 12.736540 0.682721 std 8.592511 49.960477 181.144454 0.167165 19.292983 151.039033 1.106918 7.894801 0.639357 8.196795 0.465431 min 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.820000 1.000000 0.000000 0.000000 25% 16.665000 4.000000 42.000000 0.000000 48.000000 36.000000 2.000000 13.940000 1.000000 7.001500 0.000000 50% 24.240000 17.000000 145.000000 0.000000 63.000000 118.000000 3.000000 20.500000 1.000000 12.998000 1.000000 75% 31.060000 49.000000 284.000000 0.000000 78.000000 222.000000 3.000000 27.060000 2.000000 16.997900 1.000000 max 50.000000 367.000000 977.000000 1.000000 100.000000 886.000000 4.000000 41.000000 4.000000 56.996900 1.000000 #数据信息 full.info() <class pandas.core.frame.DataFrame> RangeIndex: 17379 entries, 0 to 17378 Data columns (total 12 columns): atemp 17379 non-null float64 casual 10886 non-null float64 count 10886 non-null float64 datetime 17379 non-null object holiday 17379 non-null int64 humidity 17379 non-null int64 registered 10886 non-null float64 season 17379 non-null int64 temp 17379 non-null float64 weather 17379 non-null int64 windspeed 17379 non-null float64 workingday 17379 non-null int64 dtypes: float64(6), int64(5), object(1) memory usage: 1.6+ MB3.数据清洗
3.1.缺失数据处理
无缺失数据3.2.异常值处理
条件筛选后删除 #删除<0的数据 querySer=full.loc[:]>0 #无异常数据 querySer.shape (17379, 12)3.3.数据类型转换
提取时间数据的有效信息 #提取Date full["date"] = full.datetime.apply(lambda x: x.split()[0]) #提取month full["month"]=full.datetime.apply(lambda x: x.split(-)[1]) #提取hour full["hour"]=full.datetime.apply(lambda x :(x.split()[1]).split(:)[0]) #使用get_dummies进行one-hot编码,产生虚拟变量(dummy variables) weatherDf=pd.DataFrame() weatherDf=pd.get_dummies(full[weather],prefix=weather) #将虚拟变量列添加到full full=pd.concat([full,weatherDf],axis=1)4、构建模型
相关性关系对应
相关系数r的绝对值一般在0.8以上,认为A和B有强的相关性
0.3到0.8之间,可以认为有弱的相关性
0.3以下,认为没有相关性使用相关性矩阵函数.corr(),(ascending=False) 得出与生存情况相关性的特征的降序排列
#相关性矩阵 corrDf=full.corr() #定义一个图形 fig,ax= plt.subplots() fig.set_size_inches(12, 12) sns.heatmap(corrDf,vmin=-1,vmax = 1,square = True,annot=True) plt.show()
得出结论:温度、湿度与用户量的相关性更高
5.数据可视化
分两类因素进行分析:
5.1. 环境因素
5.2. 时间因素5.1. 1季节对使用人数的影响
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) sns.boxplot(x="season",y="count",data=full,ax=axes[0]); sns.boxplot(x="season",y="registered",data=full,ax=axes[1]); sns.boxplot(x="season",y="casual",data=full,ax=axes[2]); plt.show() D:\360downloads\Anaconda Prompt\lib\site-packages\seaborn\categorical.py:462: FutureWarning: remove_na is deprecated and is a private function. Do not use. box_data = remove_na(group_data)
夏季、秋季使用人数较多。春季使用人数最少。
5.1.2 天气因素
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) sns.boxplot(x="weather",y="count",data=full,ax=axes[0]); sns.boxplot(x="weather",y="registered",data=full,ax=axes[1]); sns.boxplot(x="weather",y="casual",data=full,ax=axes[2]); plt.show() D:\360downloads\Anaconda Prompt\lib\site-packages\seaborn\categorical.py:462: FutureWarning: remove_na is deprecated and is a private function. Do not use. box_data = remove_na(group_data)
天气越好,使用人数越多,大雨、大雪等极端天气下几乎没有用户使用。
5.1.3 温度
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) full.groupby(temp).mean()["count"].plot(linestyle="-",color="b",ax=axes[0],legend=["wendu "]) full.groupby(atemp).mean()["count"].plot(linestyle="-",color=g,ax=axes[0]) plt.legend(["温度","体感温度"]) full.groupby(temp).mean()["registered"].plot(linestyle="-",color="b",ax=axes[1]) full.groupby(atemp).mean()["registered"].plot(linestyle="-",color=g,ax=axes[1]) plt.legend(["温度","体感温度"]) full.groupby(temp).mean()["casual"].plot(linestyle="-",color="b",ax=axes[2]) full.groupby(atemp).mean()["casual"].plot(linestyle="-",color=g,ax=axes[2]) plt.legend(["温度","体感温度"]) plt.show()
温度越高,用户使用率越高;温度高于37°C,体感温度高于34°C时,用户使用率降低。
5.1.4 湿度
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) full.groupby(humidity).mean()["count"].plot(linestyle=-,color=b,ax=axes[0],legend=" ") full.groupby(humidity).mean()["registered"].plot(linestyle="-",color=g,ax=axes[1],legend=" ") full.groupby(humidity).mean()["casual"].plot(linestyle="-",color=r,ax=axes[2],legend=" ") plt.show()
湿度为20~40时,用户使用率最高。
0~20时用户使用率较低;
湿度>20后用户使用率下降。5.1.5 风速
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) full.groupby(windspeed).mean()["count"].plot(linestyle=-,color=b,ax=axes[0],legend=" ") full.groupby(windspeed).mean()["registered"].plot(linestyle="-",color=g,ax=axes[1],legend=" ") full.groupby(windspeed).mean()["casual"].plot(linestyle="-",color=r,ax=axes[2],legend=" ") plt.show()
风速大于45时,使用人数大幅下降。
5.2.1 月份
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) sns.boxplot(x="month",y="count",data=full,ax=axes[0]); sns.boxplot(x="month",y="registered",data=full,ax=axes[1]); sns.boxplot(x="month",y="casual",data=full,ax=axes[2]); plt.show() D:\360downloads\Anaconda Prompt\lib\site-packages\seaborn\categorical.py:462: FutureWarning: remove_na is deprecated and is a private function. Do not use. box_data = remove_na(group_data)
气温最低的1、2月份使用人数最少。
5.2.2 工作日
fig, axes = plt.subplots(nrows=2,ncols=3) fig.set_size_inches(16, 8) full[full["workingday"]==0].groupby(hour).mean()["count"].plot(linestyle=-,color=b,ax=axes[0][0],legend=" ") full[full["workingday"]==0].groupby(hour).mean()["registered"].plot(linestyle=-,color=b,ax=axes[0][1],legend=" ") full[full["workingday"]==0].groupby(hour).mean()["casual"].plot(linestyle=-,color=b,ax=axes[0][2],legend=" ") full[full["workingday"]==1].groupby(hour).mean()["count"].plot(linestyle=-,color=g,ax=axes[1][0],legend=" ") full[full["workingday"]==1].groupby(hour).mean()["registered"].plot(linestyle=-,color=g,ax=axes[1][1],legend=" ") full[full["workingday"]==1].groupby(hour).mean()["casual"].plot(linestyle=-,color=g,ax=axes[1][2],legend=" ") plt.xticks(range(24),full[hour],fontsize=15) plt.show()非工作日:用户数集中在白天;
工作日: 注册用户使用时间集中在上下班高峰期;非注册用户使用时间集中在白天。5.2.3. 节假日因素
fig, axes = plt.subplots(nrows=1,ncols=3) fig.set_size_inches(16, 8) sns.boxplot(x=holiday,y=count,data=full,ax=axes[0]); sns.boxplot(x="holiday",y="registered",data=full,ax=axes[1]); sns.boxplot(x="holiday",y="casual",data=full,ax=axes[2]); plt.show() D:\360downloads\Anaconda Prompt\lib\site-packages\seaborn\categorical.py:462: FutureWarning: remove_na is deprecated and is a private function. Do not use. box_data = remove_na(group_data)对于注册用户,非节假日使用率高于节假日;
而对非注册用户,节假日使用率更高。6.结论
共享单车用户使用率对天气因素依赖性较大,用户倾向于在更好的天气、更舒适的气温湿度下使用共享单车;
风速一般情况对使用率影响不大,除非是大风天气;
朝九晚五的人群更有可能成为共享单车的注册用户,这些人群在工作日的使用时间集中在上下班高峰期;非工作日和节假日使用时间集中在白天
非注册用户对天气的要求较于注册用户更高,使用时间集中在白天。
1、2月气温较低,使用人数全年最少。