Plot number of times a value appears in a column

I have a column in a dataframe and I want to plot the total number of times that each value of this column appears:

df_2 = df['disposal_ho_group_desc_msd'].value_counts()
print(list(df_2.head(3)))

Gives the output:

[83557, 41277, 40650]

The dash code I’m using is as follows:

dcc.Graph(
        id='example-graph-2',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
		{'x': [1, 2, 3], 'y': [(list(df_2.head(3)))], 'type': 'bar', 'name': 'offenses'},
		{'x': [1, 2, 3], 'y': [83557, 41277, 40650], 'type': 'bar', 'name': 'offenses 2'},
            ],
            'layout': {
                'title': 'Dash Data Visualization 2'
            }
        }
    )

My question is why does the line ‘offenses 2’ work when ‘offenses’ doesn’t work? In my head they are functionally the same.

[(list(df_2.head(3)))] will be equivalent to [[83557, 41277, 40650]] rather than [83557, 41277, 40650]. Try changing y entry to simply list(df_2.head(3))?

1 Like

Yes you are right! Thank you!