# -*- coding: utf-8 -*- import pandas as pd import matplotlib.pyplot as plt # 导入数据,并进行初步观察 lianjia_df = pd.read_csv('lianjia.csv') #删除id lianjia_df.drop('Id',axis=1,inplace=True) #print(lianjia_df.head(10)) #增加新的列 lianjia_df['UnitPrice']=round(lianjia_df['Price']/lianjia_df.Size,2) mean_price=lianjia_df.groupby('Region',sort=False)['UnitPrice'].mean()#每个城区单价 print(mean_price) plt.rcParams['font.sans-serif']=['SimHei'] y=mean_price x=lianjia_df.Region.unique() plt.figure(figsize=(25,12)) plt.bar(x,y)