【发布时间】:2021-11-14 12:13:21
【问题描述】:
我正在将 CSV 文件读入数据框并尝试绘制堆积条形图。对于每个国家/地区,我必须将正数、负数和中性数堆叠为条形图。
我的数据如下所示。
country sentiment count
India positive 10
India negative 7
Pakistan positive 120
Pakistan negative 10
Pakistan neutral 3
Australi positive 35
NewZealand positive 20
NewZealand negative 20
NewZealand neutral 0
我无法绘图。
df = pd.read_csv("C:\\Users\\sentiment_by_location.csv")
df = df.sort_values(by=['count'], ascending=False)
html.H2(children='''Sentiments by Location'''),
dcc.Graph(
id='sentimet-location',
figure={
'data': [
go.Bar(
x=df['location'],
y=[df['sentiment'], df['count']]
)
],
'layout': {
'title': 'Sentiment By Location'
}
}
)
输出图不是所需的堆叠格式。
【问题讨论】:
标签: python bar-chart plotly-dash plotly-python