2021年5月3日星期一

Plotly Choropleth Issues with Custom Polygons

My approach to creating a choropleth map via plotly seems pretty straightforward--load in the DataFrame, assign the necessary features, and plot.

Obviously there is a missed step, or an incorrect assignment somewhere in my process.

"MALL" is not shown in the below print out of geo_df.head(), but it's the column name is correct.

The code:

import pandas as pd  import plotly.express as px  import geopandas as gpd    # reading in the shapefile  path = 'my/path/goes/here'  df = pd.read_excel(path)    fig = px.choropleth(geo_df,                        locations="Geometry",                        color="MALL",                        hover_name="MWS_ID",                       locationmode = 'USA-states')     fig.update_layout(      title_text = 'Sample Title',      geo_scope='usa',    )    fig.show()  

The output:

enter image description here

Obviously data is missing.

Here is a small sample of the DataFrame geo_df:

MWS_ID   MALL   Geometry  AL_state   35000   POLYGON ((-81.29399115613001 29.90531910378, -81.29297615613 29.90665060378, -81.28482815612 29.90829460379, -81.28199765612 29.90401060378, -81.27765665611 29.90026110378, -81.27586365611 29.89649010378, -81.27329265611 29.88764010377, -81.27098065611 29.88233010376, -81.27147665611 29.87966910376, -81.26943965610999 29.87612910376, -81.2650606561 29.85907960374, -81.2629471561 29.82118010371, -81.2582931561 29.79348010368, -81.25314315609 29.77330960366, -81.23883815608001 29.73576910363, -81.22765365607 29.71416110361, -81.22637915607 29.7083701036, -81.22894265607 29.7074796036, -81.23095715607 29.7112596036, -81.23428365607001 29.71438010361, -81.24320965608 29.71973060361, -81.24421715608 29.72262960361, -81.24575815608 29.72440910362, -81.24754315609 29.72797960362, -81.24701715609 29.72998060362, -81.24651315609 29.72886110362001, -81.24523915608 29.72731010362, -81.24344615608 29.73086910362, -81.24574265608 29.73086910362, -81.24574265608 29.73154060362, -81.24241615608 29.73332010362, -81.24268365608 29.73465910362, -81.24521615608001 29.73377060362, -81.24677265609 29.73065010362, -81.24803915609 29.73065010362, -81.24445365608 29.73911110363, -81.24445365608 29.74333960363, -81.24749765609 29.74736010363999, -81.25031265609 29.75979060365, -81.25389865609 29.76199910365, -81.2572326561 29.76931010366, -81.2615736561 29.77351960366, -81.2643966561 29.77816960367, -81.2677231561 29.78104010367, -81.26746365610001 29.78681010367, -81.26899715611 29.78947060368, -81.27028665611 29.79500960368, -81.27259065611 29.79743960368, -81.27310965610999 29.80011010369, -81.27644365611 29.80896960369, -81.27797715611 29.80874060369, -81.27847265611 29.80874060369, -81.28000665611999 29.80940060369, -81.28537765612 29.80938910369, -81.28843665612 29.8104991037, -81.29022215613 29.8127096037, -81.29228215613 29.82179060371, -81.29485315613 29.82621960371, -81.29765315613 29.82798960371, -81.29945365613 29.82998060371, -81.29995715613001 29.83065010371, -81.30072015614 29.83242010372, -81.29741665613 29.84350960373, -81.29846215613 29.84837910373, -81.30180365614 29.85214060373, -81.30664815614 29.85523010374, -81.30790715614 29.85700010374, -81.30664065614 29.85811060374, -81.30487065614 29.86565010375, -81.29929365613 29.87652010376, -81.29853065613 29.88426960376, -81.29547115613001 29.88249960376, -81.29725665613 29.88448910376, -81.29955315613 29.88648010377, -81.29905715613 29.88804060377, -81.30058265613999 29.88825010377, -81.30365765614 29.89156910377, -81.30493915613999 29.89732910378, -81.30341315614 29.89954010378, -81.29984265613 29.90088060378, -81.29781365613 29.89999960378, -81.29575365613 29.89600960377, -81.29293815613001 29.89114960377, -81.28959665613 29.88950160377, -81.28298165612 29.88585110377, -81.28324115612 29.88939110377, -81.28964215613 29.90023060378, -81.29399115613001 29.90531910378))     AR_state   999500   POLYGON ((-73.65189364901001 40.58253861373, -73.66674064903 40.58343111373, -73.70268264905999 40.58340061373, -73.71041114907 40.58428961373, -73.71665964907 40.58451861373, -73.71961964908 40.58541861373, -73.72318264908 40.58518961373, -73.72409064908 40.58631111373, -73.72675314908 40.58541861373, -73.72884364908001 40.58586111373, -73.72972864908 40.58631111373, -73.73150614909 40.58564011373, -73.73654914909 40.58630011373, -73.73835014909 40.58586111373, -73.73892964909 40.58676161373, -73.7436906491 40.58652111373, -73.75344864911 40.58475111373, -73.75463114911 40.58541861373, -73.75198364911 40.58815011373, -73.7445981491 40.59286111374, -73.73985314909 40.59307861374, -73.73271164909001 40.59151061374, -73.72052014908 40.58993911373, -73.69200114905 40.58906161373, -73.68576814904 40.58974061373, -73.68103014904 40.59268961374, -73.67269914903 40.59313961374, -73.65902714902001 40.59474161374, -73.61683664898 40.59545911374, -73.61685964898 40.59749961374, -73.61566914898 40.59770961374, -73.61418164897999 40.59635911374, -73.61150364897 40.59635911374, -73.60764314897 40.59478011374, -73.59900664896 40.59500861374, -73.59456614896 40.59412011374, -73.58535014895 40.59368111374, -73.58238964895 40.59481811374, -73.57644664894001 40.59526811374, -73.57554614894001 40.59188061374, -73.57791114894 40.58621961373, -73.58265664895001 40.58462911373, -73.58978264895001 40.58417911373, -73.59455114895999 40.58665861373, -73.60733014896999 40.58779161373, -73.62634264899 40.58594911373, -73.64534014901 40.58255011373, -73.65189364901001 40.58253861373))  AZ_1   340   POLYGON ((-112.5322367924721 37.00085190580384, -112.5411021226547 36.99175950513135, -112.5302594720623 36.95144690468901, -112.5640730830554 36.89198522423338, -112.6056216977629 36.80737995586956, -112.6109658570634 36.78467622614804, -112.6129121263461 36.74833200593758, -112.635492644415 36.67585409130478, -112.619252006859 36.6139218752868, -112.6481541983599 36.55826238684474, -112.6556351686029 36.52918983790126, -112.6401015172128 36.49306397483414, -112.6257175955063 36.48413490275882, -112.6245693597086 36.46879545978954, -112.6393506589738 36.4509780979522, -112.6358630377282 36.42622738637185, -112.6263916487859 36.42262313096631, -112.629923042503 36.39255270144857, -112.6445998760296 36.38411591391134, -112.6548220676068 36.35839820522677, -112.6806826051924 36.34349955382283, -112.6952029497252 36.35265448621703, -112.724194180867 36.34642370472069, -112.7196287443173 36.32635036995785, -112.7262531820459 36.31838397254068, -112.7484082362182 36.32403085941426, -112.7565635938594 36.322814633111, -112.7646929886691 36.30654444473884, -112.7831747118712 36.301142132377, -112.790688667476 36.28919012222024, -112.8020683866988 36.28603198540087, -112.8271438962289 36.28765671187658, -112.8405092804522 36.28024961397333, -112.8677668418357 36.28248582655706, -112.8794102279684 36.27056775285347, -112.8996683840359 36.25199192738085, -112.9179896008513 36.25643506500866, -112.9275525538539 36.25360283372955, -112.9327877767777 36.24573389487266, -112.9781794573952 36.23359477928722, -113.0082994668848 36.23667638235676, -113.041978322368 36.22607082654907, -113.0589314558578 36.20364937511435, -113.0883279645143 36.19375184186215, -113.1301381103881 36.17106787567312, -113.1525663043912 36.17531553057849, -113.1992369090306 36.15147852352496, -113.1987787541198 36.12306286335499, -113.2261593076141 36.09292478472509, -113.3100188275719 36.09767390426014, -113.348653797247 36.05006167844395, -113.3437288759139 36.00728378834506, -113.3374182422596 35.98444040786737, -113.3222313373632 35.97826694964382, -113.3206007660001 35.95542911908451, -113.3316498999987 35.91710834359117, -113.3241534340071 35.89920980649517, -113.3116053738527 35.89475215996869, -113.3104247972569 35.8648972093826, -113.3167383440252 35.85229319469799, -113.3278259702283 35.83002546273318, -113.3324152762863 35.778967321366, -113.3268890278794 34.92080116722676, -113.3219023466273 33.99812042217836, -112.73275365905 33.99627258476046, -112.2770110325394 33.88453690317109, -112.2573995691775 33.90732959491427, -112.2437496409552 33.90912392870048, -112.231723771615 33.95497349044899, -112.2002255195593 33.97043218267051, -112.1779885472408 34.01370013808594, -112.1635197278028 34.01564262377426, -112.1592447518868 34.04978588621604, -111.912859227883 34.02180195197567, -111.7243707370342 33.99943805449243, -111.4991014454748 34.00142492581623, -111.4973612405344 34.03426232979997, -111.4762109965194 34.04540781119084, -111.4680568483593 34.06708239404543, -111.4828601715518 34.09575710295513, -111.4801287496234 34.14704820648637, -111.7066932401841 34.14953781667744, -111.7211760783562 34.16252112673574, -111.7147468071122 34.16651347281186, -111.7065725005048 34.17550172797065, -111.7040005625398 34.18191140258429, -111.6949506147476 34.18285218304189, -111.6947262775628 34.18685672229918, -111.6979934111796 34.1898584723595, -111.7091676488591 34.18740739677561, -111.7076589704601 34.19157453382959, -111.71006720828 34.19869525314684, -111.7018140399313 34.19795569132638, -111.698517130333 34.19468568883809, -111.6945053050686 34.19687539751968, -111.6917817292443 34.20491703584337, -111.6956359393705 34.21030895950731, -111.7040649441241 34.21265844472916, -111.700266520275 34.2318671167628, -111.6901437766928 34.25912048476074, -111.6805423526654 34.26190131418078, -111.6766953544714 34.2686740680288, -111.6808802367525 34.27106768695577, -111.6833694295288 34.28196688558236, -111.6668098133448 34.28616450860176, -111.6632225094009 34.29534955947715, -111.6731988109909 34.29380200264028, -111.6828167410721 34.29498333996912, -111.6842850413692 34.29947031008469, -111.6741180056941 34.30833141930871, -111.6699261164509 34.30891122754063, -111.6642978094922 34.32040996572527, -111.6633655682545 34.32994072657829, -111.6656970685117 34.33030953849409, -111.6646146156503 34.34147441906801, -111.666767051179 34.34320845882862, -111.6670476686873 34.35184061479521, -111.6574483786859 34.36904464492878, -111.6584616797466 34.38722048535485, -111.6499771585231 34.39054854220523, -111.6469881278853 34.39320127676039, -111.6313886713469 34.39434819830421, -111.6298726019721 34.39851395853515, -111.6184323502213 34.40178617022983, -111.6144306902488 34.40721511344611, -111.610768587289 34.40667263022446, -111.6010430346638 34.41981845665966, -111.5926778227466 34.42065925548965, -111.5896267168568 34.42277465714815, -111.5774767529534 34.42258081649267, -111.5548082178283 34.44045111501851, -111.5526493286746 34.46926192612206, -111.5290122501089 34.47205872611935, -111.5231303519767 34.49681798142824, -111.5068847900898 34.4982643148097, -111.5110741364916 34.46959518724957, -111.5365544770093 34.45639599252201, -111.4758968091269 34.45943228880218, -111.4755959786111 34.45350811449715, -111.5390005925799 34.42405009366235, -111.5440543362778 34.41611289597663, -111.5290167345274 34.41342239525959, -111.4734217321288 34.43609792740256, -111.4719969620086 34.41647119405365, -111.4660309325942 34.41582043113769, -111.433421783721 34.44519194948334, -111.4013886146861 34.44532492030859, -111.4026088869102 34.43199481181245, -111.4174442983491 34.43282367972856, -111.4264326405297 34.39054903759007, -111.4038607606888 34.37838266352119, -111.3884050158948 34.39030528506656, -111.3895455603194 34.39806311843648, -111.4071423812262 34.40653347573483, -111.3950740971631 34.42577741931662, -111.3580163268813 34.43841947440533, -111.3502765430638 34.42707904336364, -111.3221272775953 34.42421487445664, -111.2514060991063 34.45128229118844, -111.2466012938759 34.44918805158085, -111.2377275953014 34.43305719085022, -111.2263083524762 34.43034585920054, -111.2053476539878 34.41127547051675, -111.1755085060154 34.40750357449703, -111.153373380158 34.39607405138185, -111.1457136392797 34.37877263776031, -111.086601015278 34.39313448453468, -111.0409075288459 34.3755332019557, -111.0543545065011 34.35299184700114, -111.0450353639646 34.3417429130404, -111.0306472837881 34.34516368137906, -111.0319692965161 34.35831292046168, -111.0225894309163 34.36922311433669, -110.9968642877679 34.35098981979506, -110.9535253458618 34.31341603789113, -110.9493208694634 34.31290804482003, -110.9206346818845 34.30838673690008, -110.8823226651426 34.29089381327474, -110.8827900362509 34.28361019543282, -110.8463760544095 34.27038194053358, -110.8259221570648 34.27704493475749, -110.8245963683238 34.28771551372363, -110.8425717494126 34.30649994956429, -110.8363223772797 34.3080944418426, -110.8097684904159 34.29615312764129, -110.8062813917625 34.30657560767511, -110.777016706385 34.29980549471912, -110.7605938433402 34.28952852505071, -110.759391648952 34.2796141128454, -110.7649474375008 34.26846751622921, -110.7636154496671 34.26208944320642, -110.753381479522 34.26414072714147, -110.7404902674786 34.00436284090114, -110.0019387410351 33.9963940535353, -109.9999816065528 33.5785890290058, -109.9231858742967 33.57072280408124, -109.9136195070074 33.5737839363702, -109.9008649286938 33.57454198835936, -109.8929400574947 33.57180904227045, -109.8851674718583 33.57084631244943, -109.8496329472894 33.5498150857597, -109.8057368937232 33.48512644623828, -109.7754211949488 33.48081030884826, -109.7501437018248 33.484782613829, -109.7378324964294 33.5111299317331, -109.673933672692 33.55895606752076, -109.6688792531869 33.57525987755068, -109.6243527721513 33.58783333470647, -109.6072753319425 33.60873504595772, -109.5668152515748 33.62597966306544, -109.5272837806756 33.62252312366677, -109.5131187829836 33.6428936200501, -109.4887800012439 33.65386610281978, -109.4808690895891 33.66178173284494, -109.4796733803712 33.68925481488863, -109.4406771920044 33.71492077868765, -109.4119970096608 33.71473063473898, -109.3547870709702 33.73061066224619, -109.3648630700253 33.73895281092032, -109.3644592385823 33.75000586510767, -109.3485897523221 33.77649959826599, -109.2796697799158 33.77862650975305, -109.0465623261429 33.77788611661585, -109.0460381585757 34.03672289373132, -109.0435845372325 34.66432754878215, -109.0449228713613 35.16201480664517, -109.046296653497 36.1609817616919, -109.0412318124294 36.9980014514491, -110.0517700383052 36.99737895329648, -112.5322367924721 37.00085190580384))     CA_1   3400   POLYGON ((-124.2067518663828 41.89925396230621, -124.2191490504371 41.84805483384847, -124.2485535361498 41.78136147674621, -124.1904979795537 41.75233617515821, -124.150755863487 41.74099595160617, -124.1378206276235 41.64204791848637, -124.0638656347316 41.46265744750836, -124.1144392958725 41.20283199681986, -124.1610750527246 41.142085981331, -124.1545530569873 41.06795491476078, -124.1157772251674 41.02173051379879, -124.2939453372705 40.69734366054495, -124.36400949922 40.55782117931837, -124.4110535760607 40.44478147252559, -124.3564810826311 40.39656046824861, -124.3489876553767 40.34466790222226, -124.3560472128852 40.24736466977589, -124.1291516220005 40.11474400608417, -124.0868864036595 40.07814517776718, -124.0838157328356 40.03273974224155, -124.0692489062679 40.02108961746694, -124.0458846387526 40.02439043246073, -124.0170035822949 40.00249601198816, -123.9589749963956 39.93037228586578, -123.9286468444296 39.91007017793616, -123.8992532298003 39.85714289384373, -123.8482056896599 39.83141367199666, -123.8299790505207 39.72562006196698, -123.8001279213574 39.706783901269, -123.7879744357472 39.60378181643204, -123.7642531729591 39.56212091378945, -123.8201557683925 39.44059923449885, -123.8260665063881 39.34681794498162, -123.7819396481212 39.25157932296405, -123.7680926693148 39.18485164185537, -123.7351826457316 39.15449497437891, -123.6832682649975 39.03518246839749, -123.7150707663351 38.97320792330891, -123.7419901317348 38.95678942939369, -123.7236585475894 38.91502801633922, -123.52419181811 38.76536536082686, -123.4918107052721 38.78007826025202, -123.3653853756583 38.77685359765961, -123.3668595848537 38.81174272052616, -123.1381391465044 38.81135827248863, -123.1309937766575 38.84069155701055, -123.0806843234345 38.83797500639751, -123.0721115234589 38.85504462887321, -122.815859116712 38.84956948296092, -122.9084795099962 38.89910589900245, -122.948899612451 38.90669373530959, -122.9818263616208 38.96421090131908, -122.9877184008483 38.99264482673403, -123.0248428658698 38.99421968173257, -123.0657221984508 39.0511004202592, -123.0876154036494 39.08045058380491, -123.0861882015511 39.13611746852003, -123.0692687885983 39.17229041865821, -123.0404107985607 39.17430753035487, -122.9967054798889 39.2308850142567, -123.0134072335082 39.28325951464173, -123.0349289231588 39.33117417374379, -123.0562505804264 39.37704075063285, -123.078304064269 39.40637316738858, -123.0604974969516 39.50245245791425, -123.0149506717239 39.52220907980358, -122.931415038156 39.51370338668661, -122.9280446136865 39.53045150857272, -122.8828740007486 39.53157783176604, -122.8806492503112 39.58129437892795, -122.8908414948602 39.70951037815077, -122.9100873598082 39.71010253789724, -122.9145602717442 39.7465481542262, -122.9437936047788 39.75015572486519, -122.9425257181424 39.79805732296781, -122.9546728732872 39.83777600175642, -122.9490034935833 39.90826808597311, -122.9166429911319 39.91965423581446, -122.9498321266543 40.0228649705551, -122.9701440833935 40.10361606896092, -122.9977858175799 40.16046628497847, -122.9673767670993 40.24484493915018, -123.0664881782409 40.28905214002516, -123.061602547496 40.3161919054127, -123.0634483666419 40.34762657244704, -123.0388432761705 40.34928705390372, -123.0344363794654 40.36379452585991, -123.0103904104004 40.37015160978751, -123.0102710896989 40.3859583424793, -122.9974383291678 40.39946558299791, -123.0001451087451 40.42141753897731, -122.9590137884369 40.42418654613147, -122.9311584841638 40.43396458859672, -122.9326874128649 40.44652412592619, -122.9122796252041 40.44947360266126, -122.8929747865859 40.44442891036301, -122.8765242388345 40.48037520922204, -122.8466948581002 40.49187521092634, -122.8500792456212 40.5027498188727, -122.7912597537474 40.51617983106735, -122.7867294226957 40.53076726050838, -122.7727707846231 40.55393031342848, -122.7477212720668 40.55400274415746, -122.7205350034553 40.5716984884551, -122.6912931178043 40.57559170991436, -122.7005603219683 40.62938461055123, -122.727176572523 40.62767887808123, -122.7526337553763 40.69175604856711, -122.723561425874 40.69816673075979, -122.7054844808531 40.72199975321494, -122.7172987426233 40.74617816986142, -122.656037704341 40.78413585754361, -122.6618661915445 40.83367624933336, -122.6220584251675 40.87708955886928, -122.6076471987358 40.90753430218398, -122.6001682276455 40.97163198529362, -122.5591452854481 41.00609399323642, -122.5203553205521 41.00857202740906, -122.5201527160479 41.05864194654342, -122.5393950554536 41.06879003139514, -122.5143389971973 41.08633225393383, -122.4934087168841 41.0876704354289, -122.4560852824935 41.10371451905741, -122.4513553493238 41.16558402225478, -122.4951011015321 41.18228654747191, -122.4966162809796 41.19566215730275, -122.5243683600501 41.211858144527, -122.5170106652262 41.23479153825648, -122.5102718359194 41.24571081647241, -122.5092264019185 41.28925026816248, -122.4961829717416 41.29759446377169, -122.49786946903 41.31249013407051, -122.4727233788527 41.32012470673705, -122.5018805244562 41.33024159391875, -122.5053874017495 41.34352647600473, -122.535171774435 41.34157657268484, -122.5408442782486 41.35621818702773, -122.5640454506196 41.36670082794835, -122.5868210593968 41.35618542306798, -122.5827752151096 41.33844484763989, -122.5956141103823 41.32859706861915, -122.6272968516608 41.32650218118752, -122.6469110384436 41.32370214371725, -122.6509905009708 41.29046953684318, -122.6854960971104 41.27920279178516, -122.719955592882 41.26793730798927, -122.7255475362523 41.24812310907379, -122.7642313963318 41.23957282779738, -122.8034003802194 41.20261054673466, -122.8221590431993 41.21031559423724, -122.8367935889996 41.20038130146192, -122.8808792641326 41.20488179249837, -122.9308960354243 41.17764606950519, -122.9498081851825 41.18679869733155, -122.955006435481 41.14919590430513, -122.9638698483664 41.14115006807082, -122.9604454635844 41.1294692229979, -122.9735135624815 41.10774826282498, -122.9664883113599 41.08292633189478, -122.9531240736168 41.07043367002566, -122.9177767751603 41.07130390500472, -122.895126907036 41.03115001123929, -122.8993621204375 41.01748639485524, -122.9140755370889 41.00908278568245, -122.9181214471689 40.99395127123117, -122.9452430469599 40.99067580303073, -122.9655204810969 41.01162155124013, -123.0337222297818 41.00706114021636, -123.0501286276296 41.0282363523913, -123.0649734269856 41.05248769035456, -123.1134928670787 41.07403138288593, -123.2491692870957 41.07970452530109, -123.2699351318379 41.12255571434113, -123.2964156662649 41.14206102678656, -123.3199344157645 41.13880127698413, -123.355491595259 41.16093794804388, -123.3785687763638 41.15441101801139, -123.4089712668472 41.17032186989668, -123.4359997553931 41.2258394532351, -123.4545800435129 41.23436998639832, -123.439281116724 41.25023429401318, -123.4423505838642 41.27301271108823, -123.4652784466644 41.28123507814976, -123.4562362815148 41.29502881286343, -123.4790671640869 41.33449954786393, -123.479851720712 41.37229520756568, -123.5004580792439 41.37903726296172, -123.6589929503434 41.38718083657991, -123.6541197817213 41.39906491743645, -123.6398956957622 41.40670396980607, -123.6467623987726 41.42431521064638, -123.6197615048705 41.43455294564357, -123.612837324933 41.46309580498902, -123.6269996496212 41.47029473550447, -123.6500067987855 41.53958995222177, -123.6832888322631 41.5420554161083, -123.6916884147499 41.5546501822604, -123.6818988206555 41.59344187868484, -123.7132952223987 41.59769480523496, -123.6984655294386 41.63194917709754, -123.681045677846 41.63326635633324, -123.686506699664 41.67100545185151, -123.6658425447716 41.69582031917822, -123.6867649072481 41.77908394186549, -123.6719002878411 41.79855697983356, -123.6952361380575 41.80677836916244, -123.7056774685997 41.83267951801309, -123.6774325010754 41.83651779769738, -123.6601081692126 41.85455379433453, -123.6361415422823 41.88817139675955, -123.6046737045055 41.8855609096701, -123.5921478143578 41.90661421954488, -123.5562553841085 41.90433171252987, -123.5310152933414 41.96161727370796, -123.5303575447234 41.98859570098957, -124.2072868696752 41.98579780198695, -124.2067518663828 41.89925396230621))  

Any help is greatly appreciated! Thank you.

https://stackoverflow.com/questions/67362742/plotly-choropleth-issues-with-custom-polygons May 03, 2021 at 10:08AM

没有评论:

发表评论