*数据来自kaggle
1、认识数据
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
house_prices=pd.read_csv('E:\DESK\house_prices.csv',engine='python')
house_prices.head() #查看前5行
Out[125]:
Suburb ... CouncilArea
0 Abbotsford ... Yarra City Council
1 Abbotsford ... Yarra City Council
2 Abbotsford ... Yarra City Council
3 Aberfeldie ... Moonee Valley City Council
4 Airport West ... Moonee Valley City Council
[5 rows x 13 columns]
house_prices.describe() #展示数据的一些基础信息
Out[126]:
Rooms Price ... Propertycount Distance
count 63023.000000 4.843300e+04 ... 63023.000000 63023.000000
mean 3.110595 9.978982e+05 ... 7617.728131 12.684829
std 0.957551 5.934989e+05 ... 4424.423167 7.592015
min 1.000000 8.500000e+04 ... 39.000000 0.000000
25% 3.000000 6.200000e+05 ... 4380.000000 7.000000
50% 3.000000 8.300000e+05 ... 6795.000000 11.400000
75% 4.000000 1.220000e+06 ... 10412.000000 16.700000
max 31.000000 1.120000e+07 ... 21650.000000 64.100000
[8 rows x 5 columns]
house_prices.info() #展示了每列数据的个数、空值类型及数据类型
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 63023 entries, 0 to 63022
Data columns (total 13 columns):
Suburb 63023 non-null object
Address 63023 non-null object
Rooms 63023 non-null int64
Type 63023 non-null object
Price 48433 non-null float64
Method 63023 non-null object
SellerG 63023 non-null object
Date 63023 non-null object
Postcode 63023 non-null int64
Regionname 63023 non-null object
Propertycount 63023 non-null int64
Distance 63023 non-null float64
CouncilArea 63023 non-null object
dtypes: float64(2), int64(3), object(8)
memory usage: 6.3+ MB
2、数据整理
house_prices.isnull().sum() #计算每列值的空值个数
Out[128]:
Suburb 0
Address 0
Rooms 0
Type 0
Price 14590
Method 0
SellerG 0
Date 0
Postcode 0
Regionname 0
Propertycount 0
Distance 0
CouncilArea 0
dtype: int64
house_prices.dropna(how='any',inplace=True) #删除有空值的行
可看出数据中仅Price数据存在空值,将含有空值的行删除。
3、认识数据
- Rooms列数据有多个值,从下图可看出,房间数多分布在1-5之间。
g = sns.kdeplot(house_prices.Rooms, color="Red", shade = True)
g.set_xlabel("Rooms")
g.set_ylabel("Frequency")
plt.title('Distribution of Rooms',size = 20)