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
yis 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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With