gpt4 book ai didi

python - 所有参数应该有相同的长度 plotly

转载 作者:行者123 更新时间:2023-12-05 03:51:13 26 4
gpt4 key购买 nike

我尝试使用 plotly.express 制作条形图,但我发现了这个问题

All arguments should have the same length. The length of argument yis 51, whereas the length of previously-processed arguments ['x'] is4399and 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)

关于python - 所有参数应该有相同的长度 plotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63061398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com