"Actual Combat" The Secret of Nanjing Housing Prices-Community Prices "2"

  1. "Practice" The Secret of Nanjing Housing Prices-Preparation
  2. "Actual Combat" The Secret of Nanjing Housing Prices-Community Prices "1"

Case 2: Construction of the residential complex in Nanjing over the years-line chart

# 计算南京历年的小区建成数量
Jianzhu_tmp = Xiaoqu["建筑年代"].value_counts()
Jianzhu_year = Jianzhu_tmp.sort_index().reset_index()
Jianzhu_year.columns = ["year", "cnt"]
# 时间跨度太大,因此选择80年以后、18年以前的数据
Jianzhu_year = Jianzhu_year[(Jianzhu_year["year"]>="1980") & (Jianzhu_year["year"]<="2018")]

plt.figure(figsize=(16, 6))
# 基于plot()语句(折线)
plt.plot(Jianzhu_year["year"], Jianzhu_year["cnt"], color="#A0522D", alpha=0.9, 
         marker="o", label="小区数量", linewidth=2, linestyle="--")
plt.title("南京小区建成数量与年份的关系", fontsize=15)
plt.legend()

image description

From the results of the drawing, the highest point was in 2000, followed by 2005. Throughout the entire time axis, the speed of the construction of the community fluctuates, and it seems that there is no obvious pattern. Then let's change the perspective of which years on the chart are above the average line and which ones are below the average line.

plt.figure(figsize=(16, 6))
plt.plot(Jianzhu_year["year"], Jianzhu_year["cnt"], color="#A0522D", alpha=0.9, label="小区数量", linewidth=2, linestyle="-")

# 绘制数据的均线,并进行颜色填充,增加图形的可读性
plt.fill_between(Jianzhu_year["year"], Jianzhu_year["cnt"].mean(), Jianzhu_year["cnt"], color="#CD853F")
plt.title("南京小区建成数量与年份的关系", fontsize=15)
plt.legend()

image description

The law is very obvious. After 1998, Nanjing's urbanization has entered a very rapid development stage (the more communities are built each year, the faster the urbanization speed we believe). During the 12 years from 1998 to 2010, the number of communities built was above the historical average. This phenomenon was particularly significant in the first 5 years of the 21st century.

After 2010, the rate of urbanization began to stabilize and gradually declined. Especially in 2018, the decline was particularly pronounced. This is because 17 years later, Nanjing started the most stringent property market policies in history, such as purchase and sale and price restrictions. There were few land auctions and the market was very deserted.

In addition, this picture can still be seen from the side of the government's control of the rhythm of land auctions.

How is this picture realized? Comparative drawing down two statements, in addition to the change point plot () statement parameter fine-tuning, is that increased fill_between () statement. The purpose of this sentence is to fill the part between the two curves with the specified color. The first parameter represents the range of the x-axis of the area to be filled, the second parameter represents the first curve (here the constant represents a straight line parallel to the x-axis), the third parameter represents the second curve, and color represents the specified Color fill. Of course, you can also increase the alpha parameter to specify the transparency of the filled color block.

Case 3: The completion status of communities in various districts under Nanjing over the years-line chart

The development of cities is usually uneven. For the city center, urbanization is close to 100%. The process of urbanization is usually accompanied by the demolition of counties and districts, and the elevation of administrative levels, which is a great benefit to the newly added administrative districts. Let's take a look at this case.

Simply put, in order to achieve our goal, the easiest way is to draw a separate drawing for each administrative district. Smart friends will surely think of simply encapsulating the drawing statement and calling it with a loop.

This little trick will be used frequently later, but here I will teach you something different: drawing multiple graphs together, unifying the coordinate axis, and making it more readable.

# 采集代绘图的行政区
Area = Xiaoqu["区县定位"].unique().tolist()

# 绘制组合图,组合图的分布位11*1,呈列分布,图层大小16×40
figure, axes = plt.subplots(len(Area), 1, figsize=(16, 40))
plt.subplots_adjust(wspace=0.2, hspace=0.3)

# 对Area中的每个行政区遍历、绘图,需要注意的是绘图语句需要指定到具体轴,例如axes[1]
for index, value in enumerate(Area):
    # 绘图前的统计运算:按照年份排序;对于数据空缺的年份,默认置0;
    Jianzhu_area = Xiaoqu[Xiaoqu["区县定位"] == value]["建筑年代"].value_counts()
    Jianzhu_area.sort_index(inplace=True)
    Jianzhu_area.columns = ["year", "cnt"]
    Jianzhu_area = Jianzhu_area.loc["1980":"2018"]
    Jianzhu_area = Jianzhu_area.reindex([str(i) for i in range(1980, 2019, 1)])
    Jianzhu_area.fillna(0, inplace=True)

    # 绘图语句
    axes[index].plot(Jianzhu_area.index.tolist(), Jianzhu_area.tolist(), color="#A0522D", alpha=0.9, label= value+"小区数量", linewidth=2, linestyle="-")
    axes[index].fill_between(Jianzhu_area.index.tolist(), Jianzhu_area.mean(), Jianzhu_area.tolist(), color="#CD853F")
    axes[index].legend()
    axes[index].set_ylim(0,85)

# 在索引为0的轴上设置标题,作为整个图片的标题
axes[0].set_title("南京下辖各区历年小区建成情况", fontsize=15)

image description

From the picture, the number of built-up communities in Nanjing’s traditional main urban areas: Xuanwu, Gulou, and Qinhuai has gradually fallen below the average since 2000, and has shrunk day by day, until now there is basically no land to sell. Since 2000, Jiangning, Yuhua, Qixia, Pukou, and Jianye have gradually increased their development efforts. The number of communities built has been increasing, but by 2018, they have all shrunk to near the average line. There is almost no data in the remote area of ​​Lishui Liuhe. The possible reason is that historical statistics are not effectively covered, so we will not analyze it here.

On the whole, Nanjing's urban sector is gradually expanding. The golden age of Nanjing real estate should be from 2000 to 2010. So far, Nanjing is gradually entering the era of "second-hand housing".

Case 4: The average price of the districts under the jurisdiction of Nanjing-box map

Usually everyone is talking about the average price, but the average price has obvious limitations, that is, a single average price can hardly reflect the level of housing prices in a certain area. In particular, two areas with the same average house price may have completely different housing composition. Therefore, I recommend using box diagrams to characterize them. Usually a box can simultaneously characterize indicators such as median, mean, upper quartile, lower quartile, upper and lower limits, and outliers, and the amount of information is very rich.

Price_mean = Xiaoqu[["区县定位", "参考均价"]].dropna()
Price_mean["参考均价"] = Price_mean["参考均价"].astype(np.int32)
# 将原始数据分块、整理
box_data = []	# 箱体图的房价数据
labels = []		# x轴的标签数据
for index, value in enumerate(Area):
    box_data.append(Price_mean[Price_mean["区县定位"] == value]["参考均价"].values.tolist())
    labels.append(value)
plt.figure(figsize=(10, 8))
plt.boxplot(box_data, # 每个箱体的绘图数据
            labels = labels, # x轴的标签名
            patch_artist=True, # 设置自定义颜色填充箱体,默认白色填充
            showmeans=True, # 显示均值
            boxprops = {
    
    'color':'black','facecolor':'blue', 
                        'color':'blue', 'alpha':0.7}, # 设置箱体属性,填充色和边框色
            flierprops = {
    
    'marker':'o','markerfacecolor':'red', 
                          'color':'black', 'alpha':0.7}, # 设置异常点的属性,包括点的形状、填充色和边框色
            meanprops = {
    
    'marker':'*','markerfacecolor':'yellow',
                         'markersize':'12'}, # 设置均值点的属性,点的形状、填充色
            medianprops = {
    
    'linestyle':'--', 
                           'color':'white'},# 设置中位数线的属性,线的类型和颜色
           )
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
plt.title("南京下辖各区小区均价情况", fontsize=15)

image description

From the above picture, the first echelon of Nanjing residential housing prices are Gulou, Jianye, Xuanwu, and Qinhuai, the second echelon is Jiangning, Yuhuatai, Pukou, and Qixia, and the third echelon is Lishui, Liuhe, and Gaochun.

From the upper quartile point of view, Jianye and Gulou took the lead, followed by Xuanwu, and the TOP brothers left behind a large portion of the other partners in the proper luxury housing area (there are also school district housing bonuses).

And we can see from the figure that the higher the price of the sector, the more severe the deviation between the mean (yellow star) and the median house price (white dotted line), the mean is generally higher than the median, this is because of the new Luxury residential quarters greatly increased the average value of the overall sector.

to sum up

From the analysis in this section, friends can basically see where Nanjing’s core urban areas, emerging areas, and just-needed areas are.

This section introduces the basic drawing methods of three types of graphs: histogram, line graph, and box graph. The histogram is mainly used to compare the size of different values, the line chart is more suitable to indicate the time trend, and the box chart is used to analyze the distribution of the data.

In the next section, we will continue to use the data of the community to chat with friends about the quantity of commercial housing in Nanjing, and look forward to it!

Guess you like

Origin blog.csdn.net/qq_33254766/article/details/108552787