In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how Python realizes the data analysis of second-hand housing prices in a certain area, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
Simple cleaning of house price data analysis data
Data.csv
Data display
# Import module import pandas as pd # import data statistics module import matplotlib # import chart module import matplotlib.pyplot as plt # import drawing module # avoid Chinese garbled matplotlib.rcParams ['font.sans-serif'] = [' SimHei'] # set font to SimHei display Chinese matplotlib.rcParams ['axes.unicode_minus'] = False # set normal display characters Use rc configuration file to customize # simple cleaning data = pd.read_csv ('data.csv') # read csv data del data [' Unnamed: 0'] # remove index column data.dropna (axis=0, how='any', inplace=True) # remove all null values data ['unit price'] = data ['unit price'] .map (lambda d: d.replace ('yuan / square meter') in data data ) # remove the unit price "yuan / square meter" from data ['unit price'] = data ['unit price'] .astype (float) # convert the unit price to floating point type Float (data [', unit price]) data ['total price'] = data ['total price'] .map (lambda d: d.replace ('million,')) # remove the total price from data ['total price'] = data ['total price'] .astype (float) # convert the total house price to a floating point type Float (data [', unit price]) data ['GFA'] = data ['GFA'] .map (lambda p: p.replace ('sq m,')) # remove GFA by "sq m" data ['GFA'] = data ['GFA'] .astype (float) # convert GFA to floating point type
Average price analysis of each district # obtain the average price analysis of second-hand housing in each district, and further process the data according to the demand. If you want to write the corresponding algorithm, you need to process def get_average_price (): group = data.groupby ('area') # divide the house area into average_price_group = group ['unit price'] .mean () # calculate the average price of each region Average_price_group dictionary x = average_price_group.index # region y = average_price_group.values.astype (int) # the average price corresponding to the region a = ['t equal to a.keys () return x, y # returns the region and the corresponding average price Region pun average_price average price # shows average price bar chart def average_price_bar (x, y, title): plt.figure () # graphic canvas plt.bar (x, y) Alpha=0.8) # drawing bar graph plt.xlabel ("region") # area text plt.ylabel ("average price") # average price text plt.title (title) # table title text # numeric label for x, y in enumerate (y): plt.text (x, y + 100,y) for each figure Ha='center') plt.show () if _ name__ = ='_ main__': x, y = get_average_price () title = 'average price analysis by district' average_price_bar (x, y, title)
It runs as shown in the picture.
Analysis of the decoration degree of second-hand houses in the city # obtain the average price analysis of second-hand houses in each district, and further process the data according to the demand. If you want to write the corresponding algorithm, you need to process def get_decorate_sum (): group = data.groupby ('decoration') # divide the house area into # decorate_sum_group = group ['decoration'] .count () # calculate the average price of each area The average_price_group dictionary decorate_sum_group = group.size () # calculates the average price of each region. The average_price_group dictionary x = decorate_sum_group.index # region y = decorate_sum_group.values.astype (int) # region a = ['tregions] a.keys () return x, y # returns the region and the corresponding average price Region pun average_price average price # shows average price bar chart def average_price_bar (x, y, title): plt.figure () # graphic canvas plt.bar (x, y) Alpha=0.8) # draw bar chart plt.xlabel ("decoration type") # area text plt.ylabel ("quantity") # average price text plt.title (title) # table title text # add numeric labels for x, y in enumerate (y): plt.text (x, y + 100,y) for each graphic Ha='center') plt.show () if _ name__ = ='_ main__': x, y = get_decorate_sum () title = 'city-wide second-hand housing decoration degree analysis' average_price_bar (x, y, title)
The proportion of the number of second-hand houses in each district # obtain the proportion of second-hand houses in each district, and further process the data, if you want to write the corresponding algorithm Need to process def get_proportional_quantity () according to the data required by the algorithm: area = data ['area'] .groupby (data ['area']). Count () # number of house area grouping proportion areaName = (area). Index.values # the house area grouping proportion is named return area, and areaName# displays the average price bar chart def proportional_quantity_pie (area, areaName) Title): plt.figure () # graphic canvas plt.pie (area, labels=areaName, labeldistance=1.1, autopct='%.1f%%', shadow=True, startangle=90, pctdistance=0.7) plt.title (title, fontsize=24) # Table title text plt.legend (bbox_to_anchor= (- 0.1,1)) # author title plt.show () if _ name__ = ='_ main__': # corresponds to x Y area, areaName = get_proportional_quantity () title = 'proportion of second-hand houses in various districts' proportional_quantity_pie (area, areaName, title)
Analysis of the average price of popular households # get the analysis of popular households in each district, according to the demand, further process the data, if you want to write the corresponding algorithm Need to process def get_hot_portal () according to the data required by the algorithm: # another method to get and take the value "" group = data.groupby ('Huxing'). Size # grouping the house area into sort_data = group.sort_values (ascending=False) # decreasing the number of Household groups five_data = sort_data.head () # extracting the first five groups of Household numbers According to house_type_mean = data.groupby ('Huxing') ['unit price'] .mean (). Astype (int) # calculate the average price of each household x = house_type_ data.index. Index # Household y = house_type_ Household [five _ data.index]. Value # Household corresponding to the average price "" group = data.groupby ('Huxing') # will house Regional grouping a = group ['Huxing'] .count (). Sort_values (ascending=False). Head () # calculate the average price dictionary of each household b = group ['unit price'] .mean () [a.index] # region corresponding to the average price a = ['a.keys'] a.keys () x = b.index y = b.values.astype (int) return x Y # return region and corresponding average price Region pun average_price average price # shows average price horizontal bar def hot_portal_barh (x, y, title): plt.figure () # graphic canvas plt.barh (x, y, alpha=0.9 Color='red') # draw bar graph plt.xlabel ("average price") # area text plt.ylabel ("Huxing") # average price text plt.title (title) # Table title text plt.xlim (0, 15000) # size of X axis # add numeric labels for y, x in enumerate (y): plt.text (x + 100,100, y, str (x) + 'Yuan' for each graph Ha='left') plt.show () if _ _ name__ = ='_ _ main__': x, y = get_hot_portal () title = 'hot household average price analysis' hot_portal_barh (x, y, title)
The first three pictures are relatively simple, but the last one is more troublesome than the first three.
First get the top five popular household types, and get the average value of the corresponding household type through the household type.
Thank you for reading this article carefully. I hope the article "how to achieve data analysis of second-hand housing prices in a certain area by Python" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.