Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All arguments should have the same length plotly

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

like image 893
saas Avatar asked Aug 11 '26 14:08

saas


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)
like image 191
Daniel R Avatar answered Aug 14 '26 04:08

Daniel R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!