Binning

import numpy as np
import pandas as pd

df = pd.read_csv("../data/sample.csv")
df.head()

元号和暦西暦人口総数町名
0大正9.01920.0394748A町
1大正9.01920.031421B町
2大正9.01920.0226993C町
3大正9.01920.0253689D町
4大正9.01920.0288602E町

Binning data at each quantile

Binning based on how much of the data is X% of the total when sorted.

0.0        46.0
0.1     18002.9 <- 10%の値
0.2     20476.8
0.3     22755.0
0.4     26204.8
0.5     30824.0
0.6     45622.6
0.7     89873.9
0.8    245544.0
0.9    290714.1 <- 90%の値
1.0    765403.0
df["人口総数_ビン化"] = pd.qcut(df["人口総数"], q=11)
df[["人口総数", "人口総数_ビン化"]].head()

人口総数人口総数_ビン化
0394748(294187.0, 765403.0]
131421(28169.0, 34470.0]
2226993(214984.0, 249929.0]
3253689(249929.0, 294187.0]
4288602(249929.0, 294187.0]

Comments

(Comments will appear after approval)