{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "请读取二手车数据源,完成以下需求,在notebook中运行代码,将完整运行结果导出为pdf上传。\n", "\n", "1、车辆价格分布情况\n", "\n", "2、车辆销量品牌分布\n", "\n", "3、排放标准分析\n", "\n", "4、车龄分析\n", "\n", "5、里程分析\n", "\n", "6、折旧价格分析\n", "\n", "7、不同品牌新车平均价格对比\n", "\n", "8、排放标准与行驶里程的关系\n", "\n", "9、车龄与二手车价格的相关性" ], "id": "2ce470d74c7f8f38" }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.419400Z", "start_time": "2025-04-18T02:17:28.417330Z" } }, "cell_type": "code", "source": "import pandas as pd", "id": "ca151ea5138a6483", "outputs": [], "execution_count": 81 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.463954Z", "start_time": "2025-04-18T02:17:28.440605Z" } }, "cell_type": "code", "source": [ "car = pd.read_csv('./data/second_cars_info.csv',encoding='gbk')\n", "car.head(5)" ], "id": "cafa1492fc572672", "outputs": [ { "data": { "text/plain": [ " Brand Name Boarding_time Km Discharge排放标准 \\\n", "0 奥迪 奥迪A6L 2006款 2.4 CVT 舒适型 2006年8月 9.00万公里 国3 \n", "1 奥迪 奥迪A6L 2007款 2.4 CVT 舒适型 2007年1月 8.00万公里 国4 \n", "2 奥迪 奥迪A6L 2004款 2.4L 技术领先型 2005年5月 15.00万公里 国2 \n", "3 奥迪 奥迪A8L 2013款 45 TFSI quattro舒适型 2013年10月 4.80万公里 欧4 \n", "4 奥迪 奥迪A6L 2014款 30 FSI 豪华型 2014年9月 0.81万公里 国4,国5 \n", "\n", " Sec_price New_price \n", "0 6.90 50.89万 \n", "1 8.88 50.89万 \n", "2 3.82 54.24万 \n", "3 44.80 101.06万 \n", "4 33.19 54.99万 " ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BrandNameBoarding_timeKmDischarge排放标准Sec_priceNew_price
0奥迪奥迪A6L 2006款 2.4 CVT 舒适型2006年8月9.00万公里国36.9050.89万
1奥迪奥迪A6L 2007款 2.4 CVT 舒适型2007年1月8.00万公里国48.8850.89万
2奥迪奥迪A6L 2004款 2.4L 技术领先型2005年5月15.00万公里国23.8254.24万
3奥迪奥迪A8L 2013款 45 TFSI quattro舒适型2013年10月4.80万公里欧444.80101.06万
4奥迪奥迪A6L 2014款 30 FSI 豪华型2014年9月0.81万公里国4,国533.1954.99万
\n", "
" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 82 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.513253Z", "start_time": "2025-04-18T02:17:28.491887Z" } }, "cell_type": "code", "source": [ "from decimal import Decimal\n", "car[\"Km\"] = car[\"Km\"].str.extract(\"(\\d+\\.?\\d+)\",expand = True)\n", "car[\"New_price\"] = car[\"New_price\"].str.extract(\"(\\d+\\.?\\d+)\",expand = True)\n", "car[\"New_price\"] = car[\"New_price\"].apply(lambda x : Decimal(x) * 10000)\n", "# car[\"Sec_price\"] = car[\"Sec_price\"].apply(lambda x : Decimal(str(x)) * 10000)\n", "# car[\"Km\"] = car[\"Km\"].apply(lambda x : Decimal(str(x)) * 10000)\n", "car.head(5)" ], "id": "1094ed7ec64fd6d3", "outputs": [ { "data": { "text/plain": [ " Brand Name Boarding_time Km Discharge排放标准 \\\n", "0 奥迪 奥迪A6L 2006款 2.4 CVT 舒适型 2006年8月 9.00 国3 \n", "1 奥迪 奥迪A6L 2007款 2.4 CVT 舒适型 2007年1月 8.00 国4 \n", "2 奥迪 奥迪A6L 2004款 2.4L 技术领先型 2005年5月 15.00 国2 \n", "3 奥迪 奥迪A8L 2013款 45 TFSI quattro舒适型 2013年10月 4.80 欧4 \n", "4 奥迪 奥迪A6L 2014款 30 FSI 豪华型 2014年9月 0.81 国4,国5 \n", "\n", " Sec_price New_price \n", "0 6.90 508900.00 \n", "1 8.88 508900.00 \n", "2 3.82 542400.00 \n", "3 44.80 1010600.00 \n", "4 33.19 549900.00 " ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BrandNameBoarding_timeKmDischarge排放标准Sec_priceNew_price
0奥迪奥迪A6L 2006款 2.4 CVT 舒适型2006年8月9.00国36.90508900.00
1奥迪奥迪A6L 2007款 2.4 CVT 舒适型2007年1月8.00国48.88508900.00
2奥迪奥迪A6L 2004款 2.4L 技术领先型2005年5月15.00国23.82542400.00
3奥迪奥迪A8L 2013款 45 TFSI quattro舒适型2013年10月4.80欧444.801010600.00
4奥迪奥迪A6L 2014款 30 FSI 豪华型2014年9月0.81国4,国533.19549900.00
\n", "
" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 83 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.568207Z", "start_time": "2025-04-18T02:17:28.555681Z" } }, "cell_type": "code", "source": [ "car['Boarding_time'] = pd.to_datetime(car['Boarding_time'].str.replace('年', '-').str.replace('月', ''), errors='coerce', format='%Y-%m')\n", "car.head(3)" ], "id": "2df80c752148dcd1", "outputs": [ { "data": { "text/plain": [ " Brand Name Boarding_time Km Discharge排放标准 \\\n", "0 奥迪 奥迪A6L 2006款 2.4 CVT 舒适型 2006-08-01 9.00 国3 \n", "1 奥迪 奥迪A6L 2007款 2.4 CVT 舒适型 2007-01-01 8.00 国4 \n", "2 奥迪 奥迪A6L 2004款 2.4L 技术领先型 2005-05-01 15.00 国2 \n", "\n", " Sec_price New_price \n", "0 6.90 508900.00 \n", "1 8.88 508900.00 \n", "2 3.82 542400.00 " ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BrandNameBoarding_timeKmDischarge排放标准Sec_priceNew_price
0奥迪奥迪A6L 2006款 2.4 CVT 舒适型2006-08-019.00国36.90508900.00
1奥迪奥迪A6L 2007款 2.4 CVT 舒适型2007-01-018.00国48.88508900.00
2奥迪奥迪A6L 2004款 2.4L 技术领先型2005-05-0115.00国23.82542400.00
\n", "
" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 84 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.626329Z", "start_time": "2025-04-18T02:17:28.622360Z" } }, "cell_type": "code", "source": [ "today = pd.Timestamp('today')\n", "car['Year'] = today.year - car['Boarding_time'].dt.year\n", "car['Month'] = today.month - car['Boarding_time'].dt.month\n", "car['Year'] = car['Year'] + car['Month'] / 12" ], "id": "adb1e9029cf50440", "outputs": [], "execution_count": 85 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.693439Z", "start_time": "2025-04-18T02:17:28.689606Z" } }, "cell_type": "code", "source": [ "# 1、车辆价格分布情况\n", "car['Sec_price'].describe()" ], "id": "192ca8d230bba52c", "outputs": [ { "data": { "text/plain": [ "count 11281.000000\n", "mean 26.897567\n", "std 55.451814\n", "min 0.650000\n", "25% 5.200000\n", "50% 10.490000\n", "75% 24.800000\n", "max 808.000000\n", "Name: Sec_price, dtype: float64" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 86 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.759802Z", "start_time": "2025-04-18T02:17:28.755785Z" } }, "cell_type": "code", "source": [ "# 2、车辆销量品牌分布\n", "car['Brand'].value_counts()" ], "id": "84cd0ac0f5397e98", "outputs": [ { "data": { "text/plain": [ "别克 1350\n", "大众 991\n", "奔驰 895\n", "宝马 773\n", "奥迪 758\n", " ... \n", "东风风光 1\n", "昌河 1\n", "北汽制造 1\n", "北京 1\n", "中欧房车 1\n", "Name: Brand, Length: 104, dtype: int64" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 87 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.829496Z", "start_time": "2025-04-18T02:17:28.826138Z" } }, "cell_type": "code", "source": [ "# 3、排放标准分析\n", "car['Discharge排放标准'].value_counts()" ], "id": "abfa9e35e2c0e57b", "outputs": [ { "data": { "text/plain": [ "国4 4300\n", "欧4 1898\n", "欧5 1201\n", "国4,国5 848\n", "国3 798\n", "国5 683\n", "欧3 292\n", "-- 276\n", "国2 241\n", "国4,京5 223\n", "国3,OBD 119\n", "OBD 90\n", "国4,OBD 63\n", "欧4,OBD 62\n", "OBD,国5 38\n", "欧6 36\n", "国4,OBD,国5 31\n", "国5,京5 22\n", "欧5,OBD 9\n", "欧4,欧5 9\n", "欧5,国4 7\n", "欧4,国3 7\n", "国4,OBD,京5 6\n", "欧4,国4 6\n", "欧4,国4,OBD 5\n", "欧3,欧4 2\n", "欧5,国5 2\n", "国4,国5,京5 1\n", "欧1 1\n", "欧2 1\n", "京5 1\n", "国3,国4 1\n", "欧4,-- 1\n", "欧5,国4,国5 1\n", "Name: Discharge排放标准, dtype: int64" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 88 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.890889Z", "start_time": "2025-04-18T02:17:28.886821Z" } }, "cell_type": "code", "source": [ "# 4、车龄分析\n", "car['Year'].describe()" ], "id": "93126f910d7182c6", "outputs": [ { "data": { "text/plain": [ "count 11188.000000\n", "mean 13.123592\n", "std 2.991405\n", "min 7.500000\n", "25% 10.750000\n", "50% 13.166667\n", "75% 15.083333\n", "max 27.333333\n", "Name: Year, dtype: float64" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 89 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:28.960584Z", "start_time": "2025-04-18T02:17:28.955583Z" } }, "cell_type": "code", "source": [ "# 5、里程分析\n", "car['Km'].describe()" ], "id": "9a5d106b4e15e8a2", "outputs": [ { "data": { "text/plain": [ "count 11184\n", "unique 968\n", "top 6.00\n", "freq 485\n", "Name: Km, dtype: object" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 90 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:17:29.031125Z", "start_time": "2025-04-18T02:17:29.024995Z" } }, "cell_type": "code", "source": [ "# 6、折旧价格分析\n", "# car = car.dropna(subset=['Km'])\n", "car[['Km', 'Sec_price']].corr()" ], "id": "52035886c7842d2f", "outputs": [ { "data": { "text/plain": [ " Sec_price\n", "Sec_price 1.0" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sec_price
Sec_price1.0
\n", "
" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 91 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:23:06.001261Z", "start_time": "2025-04-18T02:23:05.987085Z" } }, "cell_type": "code", "source": [ "# 7、不同品牌新车平均价格对比\n", "car[['Brand', 'New_price']].groupby('Brand').mean()" ], "id": "568eaf05460ebb68", "outputs": [ { "data": { "text/plain": [ " New_price\n", "Brand \n", "DS 2.644188e+05\n", "GMC 1.423178e+06\n", "Jeep 4.342455e+05\n", "MINI 3.076827e+05\n", "WEY 1.930000e+05\n", "... ...\n", "雪佛兰 1.564546e+05\n", "雪铁龙 1.655019e+05\n", "雷克萨斯 7.538173e+05\n", "雷诺 2.770526e+05\n", "马自达 2.170586e+05\n", "\n", "[104 rows x 1 columns]" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
New_price
Brand
DS2.644188e+05
GMC1.423178e+06
Jeep4.342455e+05
MINI3.076827e+05
WEY1.930000e+05
......
雪佛兰1.564546e+05
雪铁龙1.655019e+05
雷克萨斯7.538173e+05
雷诺2.770526e+05
马自达2.170586e+05
\n", "

104 rows × 1 columns

\n", "
" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 96 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:25:53.211176Z", "start_time": "2025-04-18T02:25:53.179478Z" } }, "cell_type": "code", "source": [ "# 8、排放标准与行驶里程的关系\n", "car['Km'] = pd.to_numeric(car['Km'], errors='coerce')\n", "car.groupby('Discharge排放标准')['Km'].mean()" ], "id": "4af30a35353b2754", "outputs": [ { "data": { "text/plain": [ "Discharge排放标准\n", "-- 6.302677\n", "OBD 8.320222\n", "OBD,国5 3.307105\n", "京5 2.000000\n", "国2 11.470539\n", "国3 8.524411\n", "国3,OBD 7.691681\n", "国3,国4 5.000000\n", "国4 7.075801\n", "国4,OBD 5.169841\n", "国4,OBD,京5 5.533333\n", "国4,OBD,国5 4.262258\n", "国4,京5 4.808879\n", "国4,国5 4.026185\n", "国4,国5,京5 3.400000\n", "国5 2.302224\n", "国5,京5 3.365455\n", "欧1 8.000000\n", "欧2 12.000000\n", "欧3 9.064828\n", "欧3,欧4 8.000000\n", "欧4 6.729597\n", "欧4,-- 7.500000\n", "欧4,OBD 5.134426\n", "欧4,国3 8.914286\n", "欧4,国4 6.133333\n", "欧4,国4,OBD 7.460000\n", "欧4,欧5 4.120000\n", "欧5 3.364559\n", "欧5,OBD 4.911111\n", "欧5,国4 4.382857\n", "欧5,国4,国5 7.000000\n", "欧5,国5 0.650000\n", "欧6 1.073714\n", "Name: Km, dtype: float64" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 99 }, { "metadata": { "ExecuteTime": { "end_time": "2025-04-18T02:26:08.841815Z", "start_time": "2025-04-18T02:26:08.835149Z" } }, "cell_type": "code", "source": [ "# 9、车龄与二手车价格的相关性\n", "car[['Year', 'Sec_price']].corr()" ], "id": "ab1c177ba107b9bc", "outputs": [ { "data": { "text/plain": [ " Year Sec_price\n", "Year 1.00000 -0.30768\n", "Sec_price -0.30768 1.00000" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
YearSec_price
Year1.00000-0.30768
Sec_price-0.307681.00000
\n", "
" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 100 } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }