条件语句未考虑值为0的行

时间:2019-03-01 21:45:27

标签: python pandas

我写了一条条件声明,将房价转换为幅度。但是,当我绘制一个堆叠的条形图以按年份显示房屋价格时,会得到一个专门针对价格为0美元的房屋的条形图。我希望这些房屋属于0- $ 200k的类别

conditions = [
    (housing_data['sale_price'] < 200000) | (housing_data['sale_price']==0),
    (housing_data['sale_price'] > 200000) & (housing_data['sale_price'] < 400000),
    (housing_data['sale_price'] > 400000) & (housing_data['sale_price'] < 600000),
    (housing_data['sale_price'] > 600000) & (housing_data['sale_price'] < 800000),
    (housing_data['sale_price'] > 800000) & (housing_data['sale_price'] < 1000000),
    (housing_data['sale_price'] > 1000000) & (housing_data['sale_price'] < 10000000),
    (housing_data['sale_price'] > 10000000) & (housing_data['sale_price'] < 100000000),
]
choices =['$0-$200k','$200k-$400k','$400k-$600k','$600k-$800k','$800k-$1mlln','$1mlln-$10mlln','$10mlln-$100mlln']
housing_data['price_range'] = np.select(conditions,choices)
ax = housing_data.groupby(['year_of_sale','price_range']).size().unstack().plot.bar(stacked=True)
horiz_offset = 1
vert_offset = 1
ax.legend(bbox_to_anchor=(horiz_offset, vert_offset))

这是我的数据样本

{'Unnamed: 0': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10}, 'borough': {0: 3, 1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 3, 8: 3, 9: 3}, 'neighborhood': {0: 'DOWNTOWN-METROTECH', 1: 'DOWNTOWN-FULTON FERRY', 2: 'BROOKLYN HEIGHTS', 3: 'MILL BASIN', 4: 'BROOKLYN HEIGHTS', 5: 'WILLIAMSBURG-SOUTH', 6: 'BROOKLYN HEIGHTS', 7: 'WILLIAMSBURG-NORTH', 8: 'WILLIAMSBURG-SOUTH', 9: 'NAVY YARD'}, 'building_class_category': {0: '28  COMMERCIAL CONDOS', 1: '29  COMMERCIAL GARAGES', 2: '21  OFFICE BUILDINGS', 3: '22  STORE BUILDINGS', 4: '26 OTHER HOTELS', 5: '31  COMMERCIAL VACANT LAND', 6: '21 OFFICE BUILDINGS', 7: '08  RENTALS - ELEVATOR APARTMENTS', 8: '29  COMMERCIAL GARAGES', 9: '30  WAREHOUSES'}, 'tax_class': {0: '4', 1: '4', 2: '4', 3: '4', 4: '4', 5: '4', 6: '4', 7: '2', 8: '4', 9: '4'}, 'block': {0: 140, 1: 54, 2: 204, 3: 8470, 4: 230, 5: 2428, 6: 250, 7: 2307, 8: 2128, 9: 1876}, 'lot': {0: 1001, 1: 1, 2: 1, 3: 55, 4: 1, 5: 1, 6: 44, 7: 1, 8: 5, 9: 1}, 'easement': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'building_class': {0: 'R5', 1: 'G7', 2: 'O6', 3: 'K6', 4: 'H8', 5: 'V1', 6: 'O4', 7: 'D8', 8: 'G7', 9: 'E9'}, 'address': {0: '330 JAY STREET', 1: '85 JAY STREET', 2: '29 COLUMBIA HEIGHTS', 3: '5120 AVENUE U', 4: '21 CLARK STREET', 5: '329 KENT AVENUE', 6: '16 COURT STREET', 7: '250 N 10 STREET', 8: '418 KENT AVENUE', 9: '9-47 HALL ST'}, 'apartment_number': {0: 'COURT', 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'zip_code': {0: 11201, 1: 11201, 2: 11201, 3: 11234, 4: 11201, 5: 11249, 6: 11241, 7: 11211, 8: 11249, 9: 11205}, 'residential_units': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 234, 8: 0, 9: 0}, 'commercial_units': {0: 1, 1: 0, 2: 0, 3: 123, 4: 1, 5: 0, 6: 102, 7: 3, 8: 0, 9: 1}, 'total_units': {0: 1, 1: 0, 2: 0, 3: 123, 4: 1, 5: 0, 6: 102, 7: 237, 8: 0, 9: 1}, 'land_sqft': {0: 0.0, 1: 134988.0, 2: 32000.0, 3: 905000.0, 4: 20267.0, 5: 57600.0, 6: 12500.0, 7: 50173.0, 8: 44704.0, 9: 113800.0}, 'gross_sqft': {0: 0.0, 1: 0.0, 2: 304650.0, 3: 2548000.0, 4: 356000.0, 5: 0.0, 6: 290440.0, 7: 241764.0, 8: 0.0, 9: 547000.0}, 'year_built': {0: 2002, 1: 0, 2: 1924, 3: 1970, 4: 1927, 5: 0, 6: 1928, 7: 2012, 8: 0, 9: 1912}, 'tax_class_at_sale': {0: 4, 1: 4, 2: 4, 3: 4, 4: 4, 5: 4, 6: 4, 7: 2, 8: 4, 9: 4}, 'building_class_at_sale': {0: 'R5', 1: 'G7', 2: 'O6', 3: 'K6', 4: 'H8', 5: 'V1', 6: 'O4', 7: 'D8', 8: 'G7', 9: 'E9'}, 'sale_price': {0: 499401179.0, 1: 345000000.0, 2: 340000000.0, 3: 276947000.0, 4: 202500000.0, 5: 185445000.0, 6: 171000000.0, 7: 169000000.0, 8: 165000000.0, 9: 161000000.0}, 'sale_date': {0: '2008-04-23', 1: '2016-12-20', 2: '2016-08-03', 3: '2012-11-28', 4: '2017-10-31', 5: '2012-10-11', 6: '2017-10-10', 7: '2015-05-01', 8: '2015-02-04', 9: '2016-03-04'}, 'year_of_sale': {0: 2008, 1: 2016, 2: 2016, 3: 2012, 4: 2017, 5: 2012, 6: 2017, 7: 2015, 8: 2015, 9: 2016}, 'Borough': {0: nan, 1: 'BK', 2: 'BK', 3: 'BK', 4: 'BK', 5: 'BK', 6: 'BK', 7: 'BK', 8: 'BK', 9: 'BK'}, 'CD': {0: nan, 1: 302.0, 2: 302.0, 3: 318.0, 4: 302.0, 5: 301.0, 6: 302.0, 7: 301.0, 8: 301.0, 9: 302.0}, 'CT2010': {0: nan, 1: 21.0, 2: 1.0, 3: 698.0, 4: 3.01, 5: 551.0, 6: 9.0, 7: 519.0, 8: 549.0, 9: 543.0}, 'CB2010': {0: nan, 1: 3017.0, 2: 1003.0, 3: 2005.0, 4: 2000.0, 5: 1009.0, 6: 1001.0, 7: 1006.0, 8: 2006.0, 9: 2003.0}, 'SchoolDist': {0: nan, 1: 13.0, 2: 13.0, 3: 22.0, 4: 13.0, 5: 14.0, 6: 13.0, 7: 14.0, 8: 14.0, 9: 14.0}, 'Council': {0: nan, 1: 33.0, 2: 33.0, 3: 46.0, 4: 33.0, 5: 33.0, 6: 33.0, 7: 33.0, 8: 33.0, 9: 35.0}, 'ZipCode': {0: nan, 1: 11201.0, 2: 11201.0, 3: 11234.0, 4: 11201.0, 5: 11249.0, 6: 11241.0, 7: 11211.0, 8: 11249.0, 9: 11205.0}, 'FireComp': {0: nan, 1: 'L118', 2: 'E205', 3: 'E323', 4: 'E205', 5: 'E221', 6: 'E205', 7: 'E229', 8: 'E221', 9: 'L119'}, 'PolicePrct': {0: nan, 1: 84.0, 2: 84.0, 3: 63.0, 4: 84.0, 5: 90.0, 6: 84.0, 7: 94.0, 8: 90.0, 9: 88.0}, 'HealthCent': {0: nan, 1: 36.0, 2: 38.0, 3: 35.0, 4: 38.0, 5: 30.0, 6: 38.0, 7: 30.0, 8: 30.0, 9: 36.0}, 'HealthArea': {0: nan, 1: 1000.0, 2: 2300.0, 3: 8822.0, 4: 2300.0, 5: 400.0, 6: 2300.0, 7: 700.0, 8: 500.0, 9: 9300.0}, 'SanitBoro': {0: nan, 1: 3.0, 2: 3.0, 3: 3.0, 4: 3.0, 5: 3.0, 6: 3.0, 7: 3.0, 8: 3.0, 9: 3.0}, 'SanitDistr': {0: nan, 1: 2.0, 2: 2.0, 3: 18.0, 4: 2.0, 5: 1.0, 6: 2.0, 7: 1.0, 8: 1.0, 9: 2.0}, 'SanitSub': {0: nan, 1: '1B', 2: '1A', 3: '4E', 4: '1A', 5: '2B', 6: '1B', 7: '3B', 8: '4A', 9: '4E'}, 'Address': {0: nan, 1: '87 JAY STREET', 2: '29 COLUMBIA HEIGHTS', 3: '5120 AVENUE U', 4: '79 WILLOW STREET', 5: '325 KENT AVENUE', 6: '16 COURT STREET', 7: '236 NORTH 10 STREET', 8: '418 KENT AVENUE', 9: '39 HALL STREET'}, 'ZoneDist1': {0: nan, 1: 'M1-2/R8', 2: 'M2-1', 3: 'M3-1', 4: 'R6', 5: 'R6', 6: 'C5-2A', 7: 'M1-2/R6A', 8: 'R7-3', 9: 'M1-2'}, 'ZoneDist2': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: 'C4-3', 9: nan}, 'ZoneDist3': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'ZoneDist4': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'Overlay1': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: 'C2-4', 6: nan, 7: nan, 8: 'C2-4', 9: nan}, 'Overlay2': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'SPDist1': {0: nan, 1: 'MX-2', 2: nan, 3: nan, 4: nan, 5: nan, 6: 'DB', 7: 'MX-8', 8: nan, 9: nan}, 'SPDist2': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'SPDist3': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'LtdHeight': {0: nan, 1: nan, 2: nan, 3: nan, 4: 'LH-1', 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'SplitZone': {0: nan, 1: 'N', 2: 'N', 3: 'N', 4: 'N', 5: 'N', 6: 'N', 7: 'N', 8: 'Y', 9: 'N'}, 'BldgClass': {0: nan, 1: 'G7', 2: 'O6', 3: 'K6', 4: 'H8', 5: 'D7', 6: 'O4', 7: 'D8', 8: 'D1', 9: 'E9'}, 'LandUse': {0: nan, 1: 10.0, 2: 5.0, 3: 5.0, 4: 8.0, 5: 4.0, 6: 5.0, 7: 3.0, 8: 3.0, 9: 6.0}, 'Easements': {0: nan, 1: 0.0, 2: 0.0, 3: 1.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}, 'OwnerType': {0: nan, 1: 'P', 2: nan, 3: nan, 4: 'X', 5: nan, 6: 'P', 7: 'P', 8: nan, 9: 'P'}, 'OwnerName': {0: nan, 1: '85 JAY STREET BROOKLY', 2: '25-30 COLUMBIA HEIGHT', 3: 'BROOKLYN KINGS PLAZA', 4: 'WATCHTOWER C/O REAL P', 5: '325 KENT LLC', 6: '16 COURT STREET OWNER', 7: 'BRKLYN NY 250 N 10TH', 8: '420 KENT AVENUE LLC', 9: 'RXR 9-47 HALL STREET'}, 'LotArea': {0: nan, 1: 134988.0, 2: 32000.0, 3: 905000.0, 4: 20267.0, 5: 57600.0, 6: 12500.0, 7: 50173.0, 8: 44704.0, 9: 113800.0}, 'BldgArea': {0: nan, 1: 0.0, 2: 304650.0, 3: 2548000.0, 4: 356000.0, 5: 382746.0, 6: 290440.0, 7: 241764.0, 8: 463427.0, 9: 547000.0}, 'ComArea': {0: nan, 1: 0.0, 2: 304650.0, 3: 2548000.0, 4: 30000.0, 5: 11200.0, 6: 290440.0, 7: 27900.0, 8: 4884.0, 9: 547000.0}, 'ResArea': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 371546.0, 6: 0.0, 7: 213864.0, 8: 458543.0, 9: 0.0}, 'OfficeArea': {0: nan, 1: 0.0, 2: 264750.0, 3: 0.0, 4: 30000.0, 5: 1822.0, 6: 274500.0, 7: 4200.0, 8: 0.0, 9: 0.0}, 'RetailArea': {0: nan, 1: 0.0, 2: 0.0, 3: 1263000.0, 4: 0.0, 5: 9378.0, 6: 15940.0, 7: 0.0, 8: 4884.0, 9: 0.0}, 'GarageArea': {0: nan, 1: 0.0, 2: 0.0, 3: 1285000.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 22200.0, 8: 0.0, 9: 0.0}, 'StrgeArea': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 1500.0, 8: 0.0, 9: 0.0}, 'FactryArea': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 547000.0}, 'OtherArea': {0: nan, 1: 0.0, 2: 39900.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}, 'AreaSource': {0: nan, 1: 7.0, 2: 2.0, 3: 2.0, 4: 2.0, 5: 2.0, 6: 2.0, 7: 2.0, 8: 2.0, 9: 2.0}, 'NumBldgs': {0: nan, 1: 0.0, 2: 1.0, 3: 4.0, 4: 1.0, 5: 1.0, 6: 1.0, 7: 1.0, 8: 2.0, 9: 13.0}, 'NumFloors': {0: nan, 1: 0.0, 2: 13.0, 3: 2.0, 4: 15.0, 5: 0.0, 6: 37.0, 7: 6.0, 8: 20.0, 9: 8.0}, 'UnitsRes': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 522.0, 6: 0.0, 7: 234.0, 8: 470.0, 9: 0.0}, 'UnitsTotal': {0: nan, 1: 0.0, 2: 0.0, 3: 123.0, 4: 1.0, 5: 525.0, 6: 102.0, 7: 237.0, 8: 472.0, 9: 1.0}, 'LotFront': {0: nan, 1: 490.5, 2: 92.42, 3: 930.0, 4: 202.0, 5: 180.0, 6: 100.0, 7: 521.25, 8: 225.08, 9: 569.0}, 'LotDepth': {0: nan, 1: 275.33, 2: 335.92, 3: 859.0, 4: 100.33, 5: 320.0, 6: 125.0, 7: 200.0, 8: 281.86, 9: 204.0}, 'BldgFront': {0: nan, 1: 0.0, 2: 335.0, 3: 0.0, 4: 202.0, 5: 179.0, 6: 92.0, 7: 500.0, 8: 0.0, 9: 304.0}, 'BldgDepth': {0: nan, 1: 0.0, 2: 92.0, 3: 0.0, 4: 100.33, 5: 315.0, 6: 125.0, 7: 100.0, 8: 0.0, 9: 80.92}, 'Ext': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'ProxCode': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 1.0, 8: 0.0, 9: 0.0}, 'IrrLotCode': {0: nan, 1: 'N', 2: 'Y', 3: 'Y', 4: 'N', 5: 'N', 6: 'Y', 7: 'N', 8: 'Y', 9: 'Y'}, 'LotType': {0: nan, 1: 5.0, 2: 3.0, 3: 3.0, 4: 3.0, 5: 3.0, 6: 3.0, 7: 1.0, 8: 5.0, 9: 3.0}, 'BsmtCode': {0: nan, 1: 5.0, 2: 5.0, 3: 5.0, 4: 2.0, 5: 5.0, 6: 2.0, 7: 2.0, 8: 5.0, 9: 5.0}, 'AssessLand': {0: nan, 1: 1571850.0, 2: 1548000.0, 3: 36532350.0, 4: 2250000.0, 5: 3110400.0, 6: 2448000.0, 7: 1354500.0, 8: 1699200.0, 9: 1282500.0}, 'AssessTot': {0: nan, 1: 1571850.0, 2: 25463250.0, 3: 149792400.0, 4: 27166050.0, 5: 5579990.0, 6: 28309500.0, 7: 23965650.0, 8: 3534300.0, 9: 11295000.0}, 'ExemptLand': {0: nan, 1: 1571850.0, 2: 0.0, 3: 0.0, 4: 2250000.0, 5: 0.0, 6: 0.0, 7: 932847.0, 8: 0.0, 9: 0.0}, 'ExemptTot': {0: nan, 1: 1571850.0, 2: 0.0, 3: 0.0, 4: 27166050.0, 5: 0.0, 6: 11304900.0, 7: 23543997.0, 8: 0.0, 9: 0.0}, 'YearBuilt': {0: nan, 1: 0.0, 2: 1924.0, 3: 1970.0, 4: 1927.0, 5: 2015.0, 6: 1928.0, 7: 2012.0, 8: 2016.0, 9: 1912.0}, 'YearAlter1': {0: nan, 1: 0.0, 2: 1980.0, 3: 0.0, 4: 1998.0, 5: 0.0, 6: 2009.0, 7: 2012.0, 8: 0.0, 9: 0.0}, 'YearAlter2': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 2000.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}, 'HistDist': {0: nan, 1: nan, 2: nan, 3: nan, 4: 'Brooklyn Heights Historic District', 5: nan, 6: 'Borough Hall Skyscraper Historic Distric', 7: nan, 8: nan, 9: nan}, 'Landmark': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'BuiltFAR': {0: nan, 1: 0.0, 2: 9.52, 3: 2.82, 4: 17.57, 5: 6.64, 6: 23.24, 7: 4.82, 8: 10.37, 9: 4.81}, 'ResidFAR': {0: nan, 1: 7.2, 2: 0.0, 3: 0.0, 4: 2.43, 5: 2.43, 6: 10.0, 7: 3.0, 8: 5.0, 9: 0.0}, 'CommFAR': {0: nan, 1: 2.0, 2: 2.0, 3: 2.0, 4: 0.0, 5: 0.0, 6: 10.0, 7: 2.0, 8: 0.0, 9: 2.0}, 'FacilFAR': {0: nan, 1: 6.5, 2: 0.0, 3: 0.0, 4: 4.8, 5: 4.8, 6: 10.0, 7: 3.0, 8: 5.0, 9: 4.8}, 'BoroCode': {0: nan, 1: 3.0, 2: 3.0, 3: 3.0, 4: 3.0, 5: 3.0, 6: 3.0, 7: 3.0, 8: 3.0, 9: 3.0}, 'BBL': {0: nan, 1: 3000540001.0, 2: 3002040001.0, 3: 3084700055.0, 4: 3002300001.0, 5: 3024280001.0, 6: 3002500044.0, 7: 3023070001.0, 8: 3021280005.0, 9: 3018760001.0}, 'CondoNo': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}, 'Tract2010': {0: nan, 1: 21.0, 2: 1.0, 3: 698.0, 4: 301.0, 5: 551.0, 6: 9.0, 7: 519.0, 8: 549.0, 9: 543.0}, 'XCoord': {0: nan, 1: 988208.0, 2: 985952.0, 3: 1006597.0, 4: 985622.0, 5: 993500.0, 6: 986784.0, 7: 997307.0, 8: 992807.0, 9: 993650.0}, 'YCoord': {0: nan, 1: 195011.0, 2: 195007.0, 3: 161424.0, 4: 193713.0, 5: 199202.0, 6: 191977.0, 7: 200618.0, 8: 198027.0, 9: 193137.0}, 'ZoneMap': {0: nan, 1: '12d', 2: '12d', 3: '23b', 4: '12d', 5: '12d', 6: '12d', 7: '13a', 8: '12d', 9: '12d'}, 'ZMCode': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: nan, 8: nan, 9: nan}, 'Sanborn': {0: nan, 1: '302 016', 2: '302 004', 3: '319 077', 4: '302 014', 5: '303 007', 6: '302 018', 7: '304 018', 8: '303 006', 9: '302 049'}, 'TaxMap': {0: nan, 1: 30101.0, 2: 30106.0, 3: 32502.0, 4: 30106.0, 5: 30806.0, 6: 30107.0, 7: 30804.0, 8: 30801.0, 9: 30701.0}, 'EDesigNum': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan, 5: 'E-337', 6: nan, 7: 'E-138', 8: 'R-47', 9: nan}, 'APPBBL': {0: nan, 1: 3000540001.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 3023070001.0, 8: 3021280005.0, 9: 0.0}, 'APPDate': {0: nan, 1: '12/06/2002', 2: nan, 3: nan, 4: nan, 5: nan, 6: nan, 7: '10/08/2013', 8: '10/29/2014', 9: nan}, 'PLUTOMapID': {0: nan, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0, 5: 1.0, 6: 1.0, 7: 1.0, 8: 1.0, 9: 1.0}, 'FIRM07_FLA': {0: nan, 1: nan, 2: nan, 3: 1.0, 4: nan, 5: nan, 6: nan, 7: 1.0, 8: 1.0, 9: nan}, 'PFIRM15_FL': {0: nan, 1: nan, 2: nan, 3: 1.0, 4: nan, 5: nan, 6: nan, 7: nan, 8: 1.0, 9: nan}, 'Version': {0: nan, 1: '17V1.1', 2: '17V1.1', 3: '17V1.1', 4: '17V1.1', 5: '17V1.1', 6: '17V1.1', 7: '17V1.1', 8: '17V1.1', 9: '17V1.1'}, 'MAPPLUTO_F': {0: nan, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}, 'SHAPE_Leng': {0: nan, 1: 1559.88914353, 2: 890.718521021, 3: 3729.78685686, 4: 620.761169374, 5: 1006.33799946, 6: 460.03168012300006, 7: 1385.27352839, 8: 992.915660585, 9: 1565.91477261}, 'SHAPE_Area': {0: nan, 1: 140131.577176, 2: 34656.4472405, 3: 797554.847834, 4: 21360.1476315, 5: 58564.8643115, 6: 12947.145471, 7: 50772.624868800005, 8: 47019.5677861, 9: 118754.78573699998}, 'price_range': {0: '0', 1: '0', 2: '0', 3: '0', 4: '0', 5: '0', 6: '0', 7: '0', 8: '0', 9: '0'}}

1 个答案:

答案 0 :(得分:1)

使用cut

进行检查
bins=[-100000000,20000,40000,60000,80000,100000,1000000,10000000]
housing_data['price_range']=pd.cut(housing_data['sale_price'],bins=bins,labels=choices )