我在下面有代码,我在为property_type字段和year_built字段创建虚拟变量。然后,我将这些数据帧与原始数据帧结合在一起。接下来我删除贷方为NaN的记录。最后,我试图将我为property_type创建的虚拟变量列和按lender分组。但是当我总结哪个不正确时,我似乎得到全0。当我总结或创建虚拟变量时,有什么我做错了吗?我在下面列出了样本数据。
Code:
propType_dummies=pd.get_dummies(data_16['property_type'])
yearBuilt_dummies=pd.get_dummies(data_16['year_built'])
data_dummies=pd.concat([data_16,propType_dummies,yearBuilt_dummies],axis=1)
# dropping records where lender is NaN
NoLenderMissing=data_dummies[pd.notnull(data_dummies['lender'])]
sum_propType=NoLenderMissing.groupby('lender')[list(propType_dummies)].sum()
print(sum_propType.describe())
Out Put:
RAPT RCON RCOO RDUP RMFD RMOB RMSC RQUA \
count 26142.0 26142.0 26142.0 26142.0 26142.0 26142.0 26142.0 26142.0
mean 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
std 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
min 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
25% 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
50% 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
75% 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
max 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
RSFR RTIM RTRI VRES
count 26142.0 26142.0 26142.0 26142.0
mean 0.0 0.0 0.0 0.0
std 0.0 0.0 0.0 0.0
min 0.0 0.0 0.0 0.0
25% 0.0 0.0 0.0 0.0
50% 0.0 0.0 0.0 0.0
75% 0.0 0.0 0.0 0.0
max 0.0 0.0 0.0 0.0
Data:
id property_address \
695169 562691875 2652 LOBELIA RD ALPINE CA 91901
695252 562884083 NaN
695285 563031163 505 MISSOURI ST MARTINEZ CA 94553
695314 563191018 NaN
695320 563229683 123 ARLENE TER SAN RAFAEL CA 94903
695324 563261078 NaN
695326 563261259 NaN
695328 563273320 433 PINE RIDGE DR SAN RAMON CA 94582
695335 563275275 NaN
695336 563275426 2146 W 75TH ST LOS ANGELES CA 90047
695342 563354643 4040 HARLINGTON CIR EL DORADO HILLS CA 95762
695345 563355362 NaN
695346 563355442 14817 SHERMAN WAY 11 VAN NUYS CA 914052260
695349 563356931 33085 FOX RD TEMECULA CA 92592
695350 563357396 NaN
695351 563357951 141 MONTICELLO AVE RIO LINDA CA 95673
695352 563358223 241 SHRIKE CIR SACRAMENTO CA 95834
695353 563358700 7098 SITIO CORAZON CARLSBAD CA 92009
695355 563359313 NaN
695357 563359925 1095 MICRO PL SAN JOSE CA 951203359
695359 563422004 101 CASCADES CIR UNION CITY CA 94587
695360 563422381 907 CHEYENNE DR WALNUT CREEK CA 94598
695361 563422415 3562 WAXWING WAY ANTIOCH CA 94509
695362 563422689 3022 MILLS DR BRENTWOOD CA 94513
695364 563429038 5225 PLA VADA DR BAKERSFIELD CA 93306
695365 563429201 8427 ZEILER AVE PANORAMA CITY CA 91402
695366 563429441 3437 SAN GABRIEL RIVER PKWY BALDWIN PARK CA 91706
695367 563429494 18029 RIVER CIR #3 CANYON COUNTRY CA 91387
695371 563430973 4695 MARLENE DR SANTA MARIA CA 93455
695375 563446919 1007 HOWARD AVE #20 ESCONDIDO CA 92029
695379 563492900 1428 PECAN GROVE DR DIAMOND BAR CA 91765
695380 563492901 1428 PECAN GROVE DR DIAMOND BAR CA 91765
695386 563503033 NaN
695391 563570048 7930 SEDAN ST CANOGA PARK CA 91304
695393 563571900 3439 ZORINA WAY SACRAMENTO CA 958264650
695396 563580926 3449 W MENDOCINO AVE STOCKTON CA 95204
695400 563633816 1869 MCFARLANE ST SAN MARINO CA 91108
695401 563634908 2134 REDCLIFF ST LOS ANGELES CA 90039
695404 563636047 9 GREENLEAF #7 IRVINE CA 92604
695414 563648161 NaN
695415 563698267 4850 EMBASSY CIR #13 LA PALMA CA 90623
695416 563706968 308 FAIRWAY DR PACIFICA CA 94044
695417 563707304 1768 CARSWELL CT SUISUN CITY CA 94585
695419 563718676 9502 ALBERT DR DUBLIN CA 945684237
695420 563719154 190 CORTSEN RD PLEASANT HILL CA 94523
695421 563719342 NaN
695422 563720222 111 S DE LACEY AVE #110 PASADENA CA 91105
695423 563721975 82058 DUNN DR INDIO CA 92203
695424 563722042 6738 HARWOOD CIR #35 PALM SPRINGS CA 92264
695425 563722207 2725 MANZANITA WAY HEMET CA 92545
buyer seller \
695169 THOMAS,KELLY L & ROBYN D HAYES,ROBYN D
695252 GONZALEZ ENT INC GONZALEZ,HERMAN
695285 SPATZ,ELAINE M TRUST SPATZ,ELAINE M
695314 HAMMOND,CHARLES & DEBI TRUST DABBAGH 2011 GRANTOR TRUST
695320 LEVITAN,KORIE E LEVITAN,HENRY
695324 MARTIN,MARCIA J 1997 TRUST MARTIN,MARCIA J
695326 STEPHENSON,REGINALD MEYER,PAIGE & MOLLY
695328 PURDY,SANDY LIVING TRUST PURDY,SANDY
695335 KODA,RYAN & SAGHI KODA,SAGHI
695336 ALBERT,ELNORA LIVING TRUST NaN
695342 MEHRANPOUR,MEHRDAD|MASSOUD-ANSARI,SONBOL NaN
695345 HMBAP LLC NaN
695346 CASTILLO,SUSAN NaN
695349 PAPICH,KEN V NaN
695350 DENKERS,ROBERT K BARAJAS,CRUZ H
695351 RIVERA,GERARDO & ELIZABETH RIVERA,GERARDO
695352 SINGH,MANJOT|KAUR,IKMAN NaN
695353 PARK,KISOO KIM,HYUNJA
695355 LARA,AURELIO & EDUWIGES LARA,AURELIO
695357 SINGH,INDRAJIT K & MADHULIKA SINGH TRUST
695359 DHILLON,KULDEEP S & AMANDIP K NaN
695360 CHANG FAMILY TRUST NaN
695361 ZEIDAN,BASHAR & DENISE NaN
695362 SCHENONE,CATHERINE C NaN
695364 SHINN,KELLY THRASHER LIVING TRUST
695365 PHAM,THYPHAM & KIMOANH T PHAM,THYPHAM
695366 MONTES,SILVINO JR & JAQUELINE NaN
695367 KIM,TAE & DIANE D KIM,TAE
695371 ADAMS,ROBERT A JR ADAMS,HELEN L
695375 MEDRANO ALEJANDRA L P|PEREZ,JAVIER PARHIZKARI,BRIAN
695379 CHAO,HSIU-SHAN BRIDGETTE INVESTMENT LLC
695380 CHAO,HSIU-SHAN YU,KUO-PIN
695386 RIZZO FAMILY LIVING TRUST CRAWFORD J A 2003 TRUST
695391 SEE,LOIS R SEE,WILLIAM L
695393 MEUSBURGER,JOSEPH & DEBRA NaN
695396 FLENNER,PAUL & VICTORIA A NaN
695400 TAYBACK,CHRISTOPHER & CLARE P NaN
695401 DAMCO TRUST MCNICHOLAS,DENNIS
695404 YATO,CHRISTOPHER M|SANCHEZ,GISELDA P NaN
695414 ROCHA,GUSTAVO & ANGELICA M GOMEZ,ALBEIRO
695415 FUJII,TETSU T|KANAMOTO,KELLY NaN
695416 BUHAGIAR,GREGORY M & KATHERINE B NaN
695417 ERVIN,CHEVELL L & TAMELA M HAINES,SHON & LISA M
695419 KUANG,XIAORONG|LU,MING KUANG,XIAORONG
695420 BALDWIN,G F & B L 2005 TRUST BALDWIN B L 2005 TRUST
695421 BEACH,LAWRENCE I BEACH,DONNA J
695422 TSAI FAMILY TRUST NaN
695423 BOESIGER,JAMES A GARCIA-BOESIGER,JENNA
695424 FUNK,DAVID|BRITTON,SHEILA NaN
695425 MERCER,GARY W & KATHY L HAUSER FAMILY TRUST
transaction_date property_id property_type transaction_amount \
695169 2016-01-04 26054756 RSFR 0
695252 2016-01-05 25209945 RSFR 0
695285 2016-01-06 28471027 RSFR 0
695314 2016-01-05 28615172 RMSC 145000
695320 2016-01-04 29945401 RCON 0
695324 2016-01-07 24979978 VRES 0
695326 2016-01-04 24371952 RCON 148000
695328 2016-01-04 113547296 RCON 0
695335 2016-01-04 30719839 RSFR 0
695336 2016-01-07 32022518 RSFR 0
695342 2016-01-05 28656587 RSFR 0
695345 2016-01-08 31513160 VRES 0
695346 2016-01-06 30740556 RCON 0
695349 2016-01-02 81983739 RSFR 0
695350 2016-01-05 27729327 RSFR 120000
695351 2016-01-04 39595918 RSFR 0
695352 2016-01-04 104958371 RSFR 0
695353 2016-01-05 122795468 RSFR 0
695355 2016-01-12 23889066 RDUP 0
695357 2016-01-08 30590667 RSFR 0
695359 2016-01-05 38367349 RSFR 0
695360 2016-01-06 28343751 RSFR 0
695361 2016-01-06 28276045 RSFR 0
695362 2016-01-07 28231813 RSFR 0
695364 2016-01-05 29231869 RSFR 186500
695365 2016-01-08 99508739 RSFR 0
695366 2016-01-08 32802312 RSFR 0
695367 2016-01-11 31039686 RCON 0
695371 2016-01-14 24678457 RSFR 0
695375 2016-01-12 25785995 RCON 260000
695379 2016-01-05 32675204 RSFR 0
695380 2016-01-05 32675204 RSFR 0
695386 2016-01-06 24753709 RMSC 182500
695391 2016-01-05 80343135 RSFR 0
695393 2016-01-04 39455719 RSFR 0
695396 2016-01-02 23860426 RSFR 0
695400 2016-01-06 31724849 RSFR 0
695401 2016-01-05 31782489 RSFR 0
695404 2016-01-08 39277369 RCON 0
695414 2016-01-14 29279706 RMOB 8500
695415 2016-01-06 39233214 RCON 0
695416 2016-01-04 24133173 RSFR 0
695417 2016-01-08 119423152 RSFR 410000
695419 2016-01-06 156790379 RSFR 0
695420 2016-01-06 28370240 RSFR 0
695421 2016-01-18 29444872 RSFR 0
695422 2016-01-08 119686348 RCON 0
695423 2016-01-11 114723813 RSFR 0
695424 2016-01-08 27353005 RCON 0
695425 2016-01-11 27736737 RMOB 0
loan_amount lender sqft year_built trans_yr
695169 0 NaN 1658 1998 2016
695252 0 NaN 824 1963 2016
695285 0 NaN 1316 1941 2016
695314 0 NaN 936 1983 2016
695320 0 NaN 1510 1973 2016
695324 0 NaN 0 0 2016
695326 0 NaN 594 1985 2016
695328 0 NaN 1314 1988 2016
695335 0 NaN 2797 1979 2016
695336 1 HUD-HOUSING/URBAN DEV 1288 1925 2016
695342 350000 PROVIDENT FNDG 2714 1998 2016
695345 2750000 FIRST CHOICE BK 0 0 2016
695346 175000 BANK OF AMERICA/IL 836 1985 2016
695349 219500 PARAMOUNT EQUITY MTG 2569 2000 2016
695350 0 NaN 1532 1957 2016
695351 172000 INTERFIRST MTG 1390 1956 2016
695352 35000 TCF NAT'L BK/AZ 3887 2004 2016
695353 400000 PROVIDENT FNDG 2462 0 2016
695355 0 NaN 1726 1910 2016
695357 358250 QUICKEN LNS 3113 1987 2016
695359 374853 FREMONT BK 1881 1999 2016
695360 665000 US BK 2285 1971 2016
695361 359100 NETWORK CAP FNDG 3620 2005 2016
695362 27600 WELLS FARGO BK NW NA 2286 1996 2016
695364 183121 THE MTG HOUSE 1775 1981 2016
695365 262500 * OTHER INSTITUTIONAL LEN 2578 2002 2016
695366 317175 RESIDENTIAL BANCORP 878 1957 2016
695367 100000 WELLS FARGO BK NW NA 1127 1983 2016
695371 0 NaN 2337 1970 2016
695375 255290 SAN DIEGO FNDG 1111 1984 2016
695379 0 NaN 2447 1973 2016
695380 0 NaN 2447 1973 2016
695386 0 NaN 0 0 2016
695391 0 NaN 1952 1958 2016
695393 183200 GUARANTEED RATE 1678 1978 2016
695396 144620 CARDINAL FIN'L 1305 1955 2016
695400 1000000 CITY NAT'L BK/CHARLESTON 1990 2015 2016
695401 0 NaN 2759 1938 2016
695404 328500 FINANCE OF AMERICA MTG 1012 1976 2016
695414 0 NaN 732 1970 2016
695415 198000 PRIVATE INDIVIDUAL 1051 1980 2016
695416 75000 TCF NAT'L BK/AZ 1050 1955 2016
695417 402573 FIRST PRIORITY FIN'L 2216 2006 2016
695419 736000 WFB NA 3729 2014 2016
695420 0 NaN 2595 1958 2016
695421 0 NaN 1756 1958 2016
695422 710400 JP MORGAN CHASE BK 2010 2007 2016
695423 0 NaN 1886 2007 2016
695424 239920 WFB NA 2027 1991 2016
695425 0 NaN 1440 1972 2016
Update:
pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.22.0
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
feather: None
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
sqlalchemy: 1.2.1
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
数据:
data_16.dtypes
id int64
property_address object
buyer object
seller object
transaction_date datetime64[ns]
property_id int64
property_type object
transaction_amount int64
loan_amount int64
lender object
sqft int64
year_built int64
trans_yr int64
dtype: object