Map Python
Pandas.map is used to map values from two series having one column same. For mapping two series, the last column of the first series should be same as index column of the second series, also the values should be unique. In the following example, two series are made from same data. code map/code function takes an arbitrary function and applies it over the elements of an iterable. An iterable, loosely speaking, is anything which allows you to loop through its elements. Consider this example, code round(2.3) 2 rou.

Import plotly.graphobjects as go # Load data frame and tidy it. Import pandas as pd df = pd. Readcsv ( ') fig = go.

Figure ( data = go. Choropleth ( locations = df 'code' , # Spatial coordinates z = df 'total exports'. Astype ( float ), # Data to be color-coded locationmode = 'USA-states', # set of locations match entries in `locations` colorscale = 'Reds', colorbartitle = 'Millions USD', )) fig.
Updatelayout ( titletext = '2011 US Agriculture Exports by State', geoscope = 'usa', # limite map scope to USA ) fig. Import plotly.graphobjects as go import pandas as pd df = pd. Readcsv ( ') for col in df. Columns: df col = df col. Astype ( str ) df 'text' = df 'state' + ' + 'Beef ' + df 'beef' + ' Dairy ' + df 'dairy' + ' + 'Fruits ' + df 'total fruits' + ' Veggies ' + df 'total veggies' + ' + 'Wheat ' + df 'wheat' + ' Corn ' + df 'corn' fig = go. Figure ( data = go. Choropleth ( locations = df 'code' , z = df 'total exports'.
Python Map Object
Astype ( float ), locationmode = 'USA-states', colorscale = 'Reds', autocolorscale = False, text = df 'text' , # hover text markerlinecolor = 'white', # line markers between states colorbartitle = 'Millions USD' )) fig. Updatelayout ( titletext = '2011 US Agriculture Exports by State(Hover for breakdown)', geo = dict ( scope = 'usa', projection = go. Projection ( type = 'albers usa' ), showlakes = True, # lakes lakecolor = 'rgb(255, 255, 255)' ), ) fig. Import plotly.graphobjects as go import pandas as pd df = pd. Readcsv ( ') fig = go. Figure ( data = go. Choropleth ( locations = df 'CODE' , z = df 'GDP (BILLIONS)' , text = df 'COUNTRY' , colorscale = 'Blues', autocolorscale = False, reversescale = True, markerlinecolor = 'darkgray', markerlinewidth = 0.5, colorbartickprefix = '$', colorbartitle = 'GDPBillions US$', )) fig.

Map Python3
Updatelayout ( titletext = '2014 Global GDP', geo = dict ( showframe = False, showcoastlines = False, projectiontype = 'equirectangular' ), annotations = dict ( x = 0.55, y = 0.1, xref = 'paper', yref = 'paper', text = 'Source: CIA World Factbook', showarrow = False ) ) fig. Import plotly.figurefactory as ff import numpy as np import pandas as pd dfsample = pd. Readcsv ( ') dfsample 'State FIPS Code' = dfsample 'State FIPS Code'. Apply ( lambda x: str ( x ). Zfill ( 2 )) dfsample 'County FIPS Code' = dfsample 'County FIPS Code'. Apply ( lambda x: str ( x ). Zfill ( 3 )) dfsample 'FIPS' = dfsample 'State FIPS Code' + dfsample 'County FIPS Code' colorscale = '#f7fbff', '#ebf3fb', '#deebf7', '#d2e3f3', '#c6dbef', '#b3d2e9', '#9ecae1', '#85bcdb', '#6baed6', '#57a0ce', '#4292c6', '#3082be', '#2171b5', '#1361a9', '#08519c', '#0b4083', '#08306b' endpts = list ( np.
Linspace ( 1, 12, len ( colorscale ) - 1 )) fips = dfsample 'FIPS'. Tolist values = dfsample 'Unemployment Rate (%)'. Tolist fig = ff. Createchoropleth ( fips = fips, values = values, scope = 'usa' , binningendpoints = endpts, colorscale = colorscale, showstatedata = False, showhover = True, asp = 2.9, titletext = 'USA by Unemployment%', legendtitle = '% u nemployed' ) fig. Template = None fig.