Pandasで指定の型だけ抽出する (Python)
df.select_dtypes(include='型')
数値データのみ抽出
###INPUT###
df.select_dtypes(include='int')
###OUTPUT###
Id MSSubClass LotArea OverallQual OverallCond YearBuilt YearRemodAdd BsmtFinSF1 BsmtFinSF2 BsmtUnfSF ... WoodDeckSF OpenPorchSF EnclosedPorch 3SsnPorch ScreenPorch PoolArea MiscVal MoSold YrSold SalePrice
0 1 60 8450 7 5 2003 2003 706 0 150 ... 0 61 0 0 0 0 0 2 2008 208500
1 2 20 9600 6 8 1976 1976 978 0 284 ... 298 0 0 0 0 0 0 5 2007 181500
2 3 60 11250 7 5 2001 2002 486 0 434 ... 0 42 0 0 0 0 0 9 2008 223500
3 4 70 9550 7 5 1915 1970 216 0 540 ... 0 35 272 0 0 0 0 2 2006 140000
4 5 60 14260 8 5 2000 2000 655 0 490 ... 192 84 0 0 0 0 0 12 2008 250000
5 6 50 14115 5 5 1993 1995 732 0 64 ... 40 30 0 320 0 0 700 10 2009 143000
6 7 20 10084 8 5 2004 2005 1369 0 317 ... 255 57 0 0 0 0 0 8 2007 307000
7 8 60 10382 7 6 1973 1973 859 32 216 ... 235 204 228 0 0 0 350 11 2009 200000
8 9 50 6120 7 5 1931 1950 0 0 952 ... 90 0 205 0 0 0 0 4 2008 129900
9 10 190 7420 5 6 1939 1950 851 0 140 ... 0 4 0 0 0 0 0 1 2008 118000
10 11 20 11200 5 5 1965 1965 906 0 134 ... 0 0 0 0 0 0 0 2 2008 129500
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1452 1453 180 3675 5 5 2005 2005 547 0 0 ... 0 28 0 0 0 0 0 5 2006 145000
1453 1454 20 17217 5 5 2006 2006 0 0 1140 ... 36 56 0 0 0 0 0 7 2006 84500
1454 1455 20 7500 7 5 2004 2005 410 0 811 ... 0 113 0 0 0 0 0 10 2009 185000
1455 1456 60 7917 6 5 1999 2000 0 0 953 ... 0 40 0 0 0 0 0 8 2007 175000
1456 1457 20 13175 6 6 1978 1988 790 163 589 ... 349 0 0 0 0 0 0 2 2010 210000
1457 1458 70 9042 7 9 1941 2006 275 0 877 ... 0 60 0 0 0 0 2500 5 2010 266500
1458 1459 20 9717 5 6 1950 1996 49 1029 0 ... 366 0 112 0 0 0 0 4 2010 142125
1459 1460 20 9937 5 6 1965 1965 830 290 136 ... 736 68 0 0 0 0 0 6 2008 147500
1460 rows × 35 columns
数値データのみが入ったデータフレームを新しく作成
###INPUT###
df2 = df.select_dtypes(include='int')
df2.info()
###OUTPUT###
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1460 entries, 0 to 1459
Data columns (total 35 columns):
Id 1460 non-null int64
MSSubClass 1460 non-null int64
LotArea 1460 non-null int64
OverallQual 1460 non-null int64
OverallCond 1460 non-null int64
YearBuilt 1460 non-null int64
YearRemodAdd 1460 non-null int64
BsmtFinSF1 1460 non-null int64
BsmtFinSF2 1460 non-null int64
BsmtUnfSF 1460 non-null int64
TotalBsmtSF 1460 non-null int64
1stFlrSF 1460 non-null int64
2ndFlrSF 1460 non-null int64
LowQualFinSF 1460 non-null int64
GrLivArea 1460 non-null int64
BsmtFullBath 1460 non-null int64
BsmtHalfBath 1460 non-null int64
FullBath 1460 non-null int64
HalfBath 1460 non-null int64
BedroomAbvGr 1460 non-null int64
KitchenAbvGr 1460 non-null int64
TotRmsAbvGrd 1460 non-null int64
Fireplaces 1460 non-null int64
GarageCars 1460 non-null int64
GarageArea 1460 non-null int64
WoodDeckSF 1460 non-null int64
OpenPorchSF 1460 non-null int64
EnclosedPorch 1460 non-null int64
3SsnPorch 1460 non-null int64
ScreenPorch 1460 non-null int64
PoolArea 1460 non-null int64
MiscVal 1460 non-null int64
MoSold 1460 non-null int64
YrSold 1460 non-null int64
SalePrice 1460 non-null int64
dtypes: int64(35)
memory usage: 399.3 KB