所有参数应该有相同的长度 plotly
All arguments should have the same length plotly
我尝试使用 plotly.express 制作条形图,但我发现了这个问题
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()
和这个数据样本
enter image description here
df['state']
包含数据框中的所有行,而 c
仅包含状态的每个唯一值的一行。你应该使用 c.index
代替:
px.bar(y=c, x=c.index)
我尝试使用 plotly.express 制作条形图,但我发现了这个问题
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()
和这个数据样本 enter image description here
df['state']
包含数据框中的所有行,而 c
仅包含状态的每个唯一值的一行。你应该使用 c.index
代替:
px.bar(y=c, x=c.index)