Data Analysis' graph problem with plotly, pandas

Viewed 53

I'm a newbie with data analysis and I'm following a course. But I have a problem with some graph.

I'm trying to make a graph with plotly's library. I'm using "Netflix TV and Show" Dataset and for view the numbers of releases for years.

First of all, I have created an array in which I put 'release_year' and 'count'

Release=netflix.groupby(['release_year','type']) \
               .size().reset_index(name='count')

Then I create a bar

fig=px.bar(Release, x='release_year', y='count',color='type', 
           labels={'x':'Anno di rilascio', 'y':'Numero di Rilasci'},
           title='Rilasci')
fig.show()
  1. First question: Why don't I see labels in bar?
  2. If I want to analyze only "2019" or compare 2018,2019 can i? I need to save in a new array 2019 releases?
1 Answers

For 1), assuming that you mean you want to see the labels when you hover over the bar, you can pass a dictionary to the hover_data parameter of px.bar.

You will notice the way the key-value pairs are interpreted when you pass them to hover_data, the keys are the column names and the values are the columns of the DataFrame you want to be displayed. I don't believe there is a way to rename the columns, so the values should be False for the old column names.

fig=px.bar(Release, x='release_year', y='count',color='type', 
           hover_data={
           'release_year':False,
           'count':False,
           'Anno di rilascio':Release['release_year'], 
           'Numero di Rilasci':Release['count']
           },
           title='Rilasci')

enter image description here

For 2) yes you will need to create a new array, but using slicing it's not too difficult.

Release_slice = Release[Release['release_year'].isin([2018, 2019])]

fig=px.bar(Release_slice, x='release_year', y='count',color='type', 
           hover_data={
           'release_year':False,
           'count':False,
           'Anno di rilascio':Release_slice['release_year'], 
           'Numero di Rilasci':Release_slice['count']
           },
           title='Rilasci')

fig.show()

enter image description here

Related