首页 > 其他分享 >车辆销售数据分析可视化实战

车辆销售数据分析可视化实战

时间:2024-07-09 15:29:50浏览次数:13  
标签:数据分析 实战 non plt df object font 可视化 null

车辆数据分析可视化实战

1.引言

“车辆销售和市场趋势数据集”提供了关于各种车辆销售交易的全面信息收集。该数据集包括年份、品牌、型号、车款、车身类型、变速箱类型、车辆识别号码(VIN)、注册州、状况评级、里程表读数、外部和内部颜色、卖家信息、Manheim市场报告(MMR)值、销售价格及销售日期等详细信息。

2.导入所需的包并加载数据集

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
#读取数据
df=pd.read_csv('/车辆销售数据/car_prices.csv')

3.数据探索

print(df.head(5))
df.info()
"""
   year   make  ... sellingprice                                 saledate
0  2015    Kia  ...      21500.0  Tue Dec 16 2014 12:30:00 GMT-0800 (PST)
1  2015    Kia  ...      21500.0  Tue Dec 16 2014 12:30:00 GMT-0800 (PST)
2  2014    BMW  ...      30000.0  Thu Jan 15 2015 04:30:00 GMT-0800 (PST)
3  2015  Volvo  ...      27750.0  Thu Jan 29 2015 04:30:00 GMT-0800 (PST)
4  2014    BMW  ...      67000.0  Thu Dec 18 2014 12:30:00 GMT-0800 (PST)

[5 rows x 16 columns]
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 558837 entries, 0 to 558836
Data columns (total 16 columns):
 #   Column        Non-Null Count   Dtype  
---  ------        --------------   -----  
 0   year          558837 non-null  int64  
 1   make          548536 non-null  object 
 2   model         548438 non-null  object 
 3   trim          548186 non-null  object 
 4   body          545642 non-null  object 
 5   transmission  493485 non-null  object 
 6   vin           558833 non-null  object 
 7   state         558837 non-null  object 
 8   condition     547017 non-null  float64
 9   odometer      558743 non-null  float64
 10  color         558088 non-null  object 
 11  interior      558088 non-null  object 
 12  seller        558837 non-null  object 
 13  mmr           558799 non-null  float64
 14  sellingprice  558825 non-null  float64
 15  saledate      558825 non-null  object 
dtypes: float64(4), int64(1), object(11)
memory usage: 68.2+ MB
"""

4.数据处理

#数据清理
print(df.isna().sum())
print(df.nunique()) 
df.drop(columns=['vin'], inplace=True)
df.dropna(axis=0, inplace=True)
df.info()
print(df.columns.to_list())
"""
year                0
make            10301
model           10399
trim            10651
body            13195
transmission    65352
vin                 4
state               0
condition       11820
odometer           94
color             749
interior          749
seller              0
mmr                38
sellingprice       12
saledate           12
dtype: int64
year                34
make                96
model              973
trim              1963
body                87
transmission         4
vin             550297
state               64
condition           41
odometer        172278
color               46
interior            17
seller           14263
mmr               1101
sellingprice      1887
saledate          3766
dtype: int64
<class 'pandas.core.frame.DataFrame'>
Index: 472325 entries, 0 to 558836
Data columns (total 15 columns):
 #   Column        Non-Null Count   Dtype  
---  ------        --------------   -----  
 0   year          472325 non-null  int64  
 1   make          472325 non-null  object 
 2   model         472325 non-null  object 
 3   trim          472325 non-null  object 
 4   body          472325 non-null  object 
 5   transmission  472325 non-null  object 
 6   state         472325 non-null  object 
 7   condition     472325 non-null  float64
 8   odometer      472325 non-null  float64
 9   color         472325 non-null  object 
 10  interior      472325 non-null  object 
 11  seller        472325 non-null  object 
 12  mmr           472325 non-null  float64
 13  sellingprice  472325 non-null  float64
 14  saledate      472325 non-null  object 
dtypes: float64(4), int64(1), object(10)
memory usage: 57.7+ MB
['year', 'make', 'model', 'trim', 'body', 'transmission', 'state', 'condition', 'odometer', 'color', 'interior', 'seller', 'mmr', 'sellingprice', 'saledate']
"""

5. 数据可视化

5.1 销量量年度变化

#销售量年度变化
plt.figure(1)
font = {'family': 'KaiTi', 'color': 'black', 'size': 16}
plt.title("车辆年产量", fontdict=font)
plt.xlabel('年份', fontdict=font)
plt.ylabel('产量', fontdict=font)
plt.xticks(range(len(np.sort(df['year'].unique()))), np.sort(df['year'].unique()))
plt.bar(range(len(np.sort(df['year'].unique()))), df['year'].value_counts().sort_index(), color='slateblue')
plt.show()

在这里插入图片描述

5.2 各品牌销售量

#不同品牌的销售量
plt.figure(2)
make_counts=df['make'].value_counts()
make_percentage = 100*make_counts/make_counts.sum()


def autopct_format(pct):
    return ('%.2f%%' % pct) if pct > 1 else ''


labels1 = [make if percentage > 1 else '' for make, percentage in zip(make_percentage.index, make_percentage)]


plt.pie(make_counts, labels=labels1, autopct=lambda pct: autopct_format(pct), startangle=120)
plt.legend(make_counts.index, loc='center right', bbox_to_anchor=(1, 0, 0.5, 1))
plt.title('车辆品牌销售量图', fontdict=font)
plt.show()

在这里插入图片描述

5.3 销量最好的与销量最差的top5

#销量最好的五种型号的汽车以及销量最差的五辆汽车
fig,(ax1,ax2)=plt.subplots(2,1)
top5=df['model'].value_counts().head(5)
tail5=df['model'].value_counts().tail(5)

sns.barplot(x=top5.index,y=top5.values,hue=top5.index,ax=ax1,palette='flare')
ax2.set_title('销量最好的五种型号的汽车', fontdict=font)
ax2.set_xlabel('',fontdict=font)
ax2.set_ylabel('销量',fontdict=font)

sns.barplot(x=tail5.index,y=tail5.values,hue=tail5.index,ax=ax2,palette='flare')
ax1.set_title('销量最差的五种型号的汽车', fontdict=font)
ax1.set_xlabel('',fontdict=font)
ax1.set_ylabel('销量',fontdict=font)
plt.show()

在这里插入图片描述

5.4 颜色对销售价格影响

#颜色对销售价格影响
color_price_summary = df.groupby('color')['sellingprice'].agg(['mean', 'median', 'max', 'min'])
print(color_price_summary)

plt.figure(4)
sns.boxplot(x='color',y='sellingprice',data=df,)
plt.xlabel('颜色',fontdict=font)
plt.ylabel('实际价格',fontdict=font)
plt.title('不同颜色之间价格分布',fontdict=font)
plt.show()

在这里插入图片描述

5.5 车辆状况与实际价格关系

#车辆状况与实际价格关系

sns.relplot(x='condition',y='sellingprice',kind='line',data=df,marker='o')
plt.xlabel('车辆状况',fontdict=font)
plt.ylabel('实际价格',fontdict=font)
plt.title('车辆状况与实际价格关系',fontdict=font)
plt.show()

在这里插入图片描述

5.6 预估价格与实际价格关系散点图

#预估市场价值与实际卖车价格,散点图
df.plot.scatter('mmr','sellingprice')
plt.show()

在这里插入图片描述

5.7 相关性分析

#相关性
plt.figure(6)
df_dummy = df[['condition','odometer','mmr','sellingprice']]
sns.heatmap(df_dummy.corr())
plt.show()

在这里插入图片描述

6 结论

1.产量逐年增加:从1990年到2010年,车辆年产量逐年增加。这段时间的增长趋势显著,特别是在2009年到2011年之间,增长更加明显。
2.品牌销量:销量集中度较高的品牌有 Ford 和 Chevrolet,这两者合计占比接近30%。此外,一些品牌的市场份额相对较小。
3.白色(white)、灰色(gray)、黑色(black)、红色(red)等主流颜色的车辆价格分布较广,且出现了许多异常值。某些特殊颜色(如lime、pink、turquoise等)的车辆价格相对集中,价格波动较小,且异常值数量较少。
4.列的相关性在-0.78到0.98之间,表明可能存在一些多重共线性
5.市场预估价格与实际价格非常相关,但仍存在一些偏离值
6.车辆状况在10到20之间时,实际价格处于低谷。此时可能是车辆最折旧的阶段,价格较低。随着车辆状况逐渐改善(状况数字变大),实际价格又出现了上升趋势,车辆状况超过20后价格稳步提升。这可能反映出较老或较稀有的经典车型,因为其收藏价值或其他因素,价格逐渐升高。

标签:数据分析,实战,non,plt,df,object,font,可视化,null
From: https://blog.csdn.net/cxl1787846957/article/details/140254262

相关文章