文章目录
- 删除(提取)评分为0的数据记录 loc[~data['评分'].isnull()]
- 空值填补0 fillna(0)
- 去重 drop_duplicates()
- 3.1 每个城市的酒店评分平均值 groupby(by=['?']).mean()
- 3.2 每个省份每个城市酒店评分的平均值 groupby(by=['?','?']).mean()
1.读取数据
data = pd.read_csv("G:\Projects\pycharmeProject\大数据比赛\data\mysql.csv")
print(data.shape)
2.数据预处理
删除(提取)评分为0的数据记录 loc[~data[‘评分’].isnull()]
data_clean = data.loc[~data['评分'].isnull()]
空值填补0 fillna(0)
data_fin_clean = data_clean.fillna(0)
去重 drop_duplicates()
data_fin_clean_dul = data_fin_clean.drop_duplicates()
3.数据汇总
3.1 每个城市的酒店评分平均值 groupby(by=[‘?’]).mean()
city_avg = data_fin_clean_dul[['城市','评分']].groupby(by=['城市']).mean().reset_index()
print(city_avg)
3.2 每个省份每个城市酒店评分的平均值 groupby(by=[‘?’,‘?’]).mean()
pro_city_avg = data_fin_clean_dul[['省份','城市','评分']].groupby(by=['省份','城市']).mean().reset_index()
print(pro_city_avg)