链家房源数据清洗和预处理(pandas)
链家房源数据清洗和预处理(pandas) 背景知识要求 摘要 正文 数据清洗 数据预处理 结论 参考 背景知识要求 Python的pandas库。 pandas官网: http://pandas.pydata.org/ 摘要 本文使用pandas库对上一篇文章:链家房源数据爬取(Scrapy) https://blog.csdn.net/qq_39206674/article/details/90114296 获取的数据进行清洗和预处理。 正文 数据清洗 原始数据部分内容如下: 数据清洗过程包括: 去除Nan数据和重复数据 去除未知和有缺失的数据 去除经过分析无用的数据(以房源为例:车位、别墅数据为无用数据) 数据清洗代码: # 读文件 df = pd . read_csv ( r 'lianjia.csv' , sep = ',' ) # 打印原始基本信息 print ( "original data rowCount: %d" % ( df . shape [ 0 ] ) ) print ( "original data colCount: %d" % ( df . shape [ 1 ] ) ) print ( df . dtypes ) # 去除Nan数据和重复数据 df . dropna ( inplace = True ) df . drop_duplicates (