Simultaneous posting on the blog: https://leoluistudio.com/blog/42/python%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e6%9d%b1%e4%ba%ac%e9%83%bd%e5%ae%b6%e8%b3%83%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e3%81%ae%e7%a0%94%e7%a9%b6-4%e3%81%ae3/
The reason is that the number of properties in the building is different. For example, if you have 50 properties per building, the weight will be 50 times that of 1 property per building when you calculate the distribution. Take the median for each building so that it is calculated evenly.
conn = sqlite3.connect(‘info.db’)
df = pd.read_sql_query(“SELECT pid,price,area FROM price”, conn)
conn.close()
df[‘municipal’] = df.apply(municipal, axis=1)
dfmedian = df.groupby([‘pid’, ‘municipal’])[‘price’, ‘area’, ‘average’].median()
dfmedian_reset = dfmedian.reset_index(level=’municipal’)
Price distribution by ward (23 wards)
#Graph
fig = go.Figure()
for i in m23_list:
dfgroup = dfmedian_reset[dfmedian_reset[‘municipal’] == i]
fig.add_trace(go.Box(x=dfgroup[‘price’], y=dfgroup[‘municipal’], boxpoints=False))
fig.update_traces(orientation=’h’, showlegend=False)
fig.update_xaxes(range=[0, 500000])
Area distribution for each ward (23 wards)
#Graph
fig = go.Figure()
for i in m23_list:
dfgroup = dfmedian_reset[dfmedian_reset[‘municipal’] == i]
fig.add_trace(go.Box(x=dfgroup[‘area’], y=dfgroup[‘municipal’], boxpoints=False))
fig.update_traces(orientation=’h’, showlegend=False)
fig.update_xaxes(range=[0, 100])
Calculate the average price (price / area)
def average(df):
return int(df[‘price’] / df[‘area’])
df[‘average’] = df.apply(average, axis=1)
Distribution of average price for each ward (23 wards)
#Graph
fig = go.Figure()
for i in m23_list:
dfgroup = dfmedian_reset[dfmedian_reset[‘municipal’] == i]
fig.add_trace(go.Box(x=dfgroup[‘average’], y=dfgroup[‘municipal’], boxpoints=False))
fig.update_traces(orientation=’h’, showlegend=False)
Relationship between average price and walking time to the station
#Dataframe processing
dfmedian_reset = dfmedian.reset_index(level=’pid’)
dfmedian_reset[‘train’] = dfmedian_reset.apply(trainminute, axis=1)
#Graph
fig = px.scatter(dfmedian_reset, x=’train’, y=’average’, height=500, width=1000)
Relationship between average price and building type
dfmedian_reset = dfmedian.reset_index(level=’pid’)
dfmedian_reset[‘type’] = dfmedian_reset.apply(buildtype, axis=1)
fig = go.Figure()
for i in (['apartment',‘Apartment’]):
dfgroup = dfmedian_reset[dfmedian_reset[‘type’] == i]
fig.add_trace(go.Box(x=dfgroup[‘price’], y=dfgroup[‘type’], boxpoints=False))
fig.update_traces(orientation=’h’, showlegend=False)
fig.update_xaxes(range=[0, 500000])
fig.update_layout(height=500, width=1000)
Relationship between average price and building type
Relationship between average price and building structure
Relationship between average price and parking lot
Relationship between average price and parking lot
Distribution of completion dates (divided into 23 wards and city areas)
Direction and price heatmap for municipalities
Recommended Posts