All arguments should have the same length plotly

Viewed 9185

I try to do a bar graph using plotly.express but I find this problem

All arguments should have the same length. The length of argument y is 51, whereas the length of previously-processed arguments ['x'] is 4399 and this my code

import pandas as pd
import plotly.express as px
df= pd.read_csv('...../datasets-723010-1257097-fatal-police-shootings-data1.csv.xls')
c = df['state'].value_counts()
fig =px.bar(c , x = df['state'])
fig.show()

and this sample of data enter image description here

1 Answers

df['state'] has all the rows from the dataframe while c only contains a row for each unique value of state. you should use c.index instead:

px.bar(y=c, x=c.index)
Related