0
 import os
 import seaborn as sns
 print(os.listdir("../input"))
 df=pd.read_csv("../input/gun-violence-data_01-2013_03-2018.csv") 

//GUN violence dataset from kaggle//

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
import plotly.graph_objs as go

b=df.state.value_counts().sort_values()
ba=pd.DataFrame(b)
ans=ba.reset_index(inplace=True) 

//creating a dataframe only containing the state names of USA and its count//

data = [ dict(type='choropleth',
     autocolorscale = False, 
     locations = ba['index'], 
     z = ba['state'], 
     locationmode = 'USA-states', 
     text = ba['index'],
     colorscale='Viridis' ) ]


layout = dict(
    title = 'US',
    geo = dict(
        scope='usa',
        projection=dict( type='albers usa' ),
        showlakes = True,
        lakecolor = 'rgb(255, 165, 255)'),)


fig = go.Figure( data=data,layout=layout )
iplot(fig)

However, whenever I run this code, Only a blank image of USA is obtained, which is blank and shows no values. please help!

Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
Aravind
  • 13
  • 1
  • Welcome to Stackoverflow! Please have a look at [MCVE]. Without the values from your dataframe or some sample data it is very hard to give you a helpful answer. – Maximilian Peters May 23 '18 at 18:30
  • Can we see some more clarification on what you did? – Mercury Platinum May 23 '18 at 18:38
  • Hi pygasm. I got the gun violence dataset(US school Shooting) from kaggle. I had wanted to do a choropleth map of the amount of shooting occurrences of each state.So i took only the state names and its occurrences and made it into a dataframe. Then i used plotly to create a choropleth plot. But all I am seeing is a USA map with no information in it. – Aravind May 23 '18 at 18:47
  • Can we see some values from your dataframe? – Mercury Platinum May 23 '18 at 18:50
  • Yeah sure.Should I send the link to the data or update it in the question? Sorry I'm new here. :( – Aravind May 23 '18 at 18:57

0 Answers0