在D:\python机器学习\数据路径下添加housing.csv文件。
数据来自于:https://github.com/ageron/handson-ml2
数据文件位于:handson-ml2-master/datasets/housing/housing.csv
新建ipynb文件。
加载数据
import pandas as pd
path='D:/python机器学习/数据/housing.csv'
f=open('D:/python机器学习/数据/housing.csv')
housing=pd.read_csv(f)
查看数据
info()
housing.info()
info()查看数据集的数据结构,如图所示。
该数据集共20640行,即20640个实例。
其中,total_bedrooms有20433个非空值,ocean_proximity的类型是object。
head()
housing.head()
head()查看数据集的前5行数据,如图所示。
value_counts()
housing['ocean_proximity'].value_counts()
value_counts()查看某列数据的分类,如图所示。
注意:column需要用中括号。
describe()
housing.describe()
describe()查看数据集的描述统计,如图所示。
其中,null值会被忽略。
hist()
%matplotlib inline
import matplotlib.pyplot as plt
housing.hist(bins=50,figsize=(20,15))
plt.show()
hist()查看数据集的每列数据的直方图,如图所示。