0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonを使って東京都家賃についての研究 (3の3)

Posted at

#結果抜粋
ブログに同時掲載:
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/


#統計の手法2

##プログラムと結果

###建物ごとに中央値を計算する

理由としては、建物の物件数が違います。例えば1ビル50物件があれば、分布を計算する時、その重みが1ビル1物件より50倍になります。均等に計算するように、建物ごとに中央値を取ります。

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)

区ごとに価格の分布(23区)

# グラフ
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])

L2no2A.png


区ごとに面積の分布(23区)

# グラフ
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])

L2no2B.png


平均価格(価格 / 面積)を計算する

def average(df):
    return int(df[price] / df[area])

df[average] = df.apply(average, axis=1)

区ごとに平均価格の分布(23区)

# グラフ
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)

L2no2D.png


平均価格と駅まで徒歩の時間の関係

# Dataframeの処理
dfmedian_reset = dfmedian.reset_index(level=pid)
dfmedian_reset[train] = dfmedian_reset.apply(trainminute, axis=1)

# グラフ
fig = px.scatter(dfmedian_reset, x=train, y=average, height=500, width=1000)

L2no3.png


平均価格と建物のタイプの関係

dfmedian_reset = dfmedian.reset_index(level=pid)
dfmedian_reset[type] = dfmedian_reset.apply(buildtype, axis=1)
fig = go.Figure()
for i in ([マンション, アパート]):
    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)

L2no4.png


##その他の結果

平均価格と建物のタイプの関係
L2no5.png


平均価格と建物構造の関係
L2no6.png


平均価格と駐車場の関係
L2no7.png


平均価格と駐車場の関係
L2no8.png


完成日の分布(23区と市部に分ける)
L2no9.png


方向と区市町村の価格ヒートマップ
L3no1.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?