在python3中,我在熊猫上有一个数据框:
import pandas as pd
import altair as alt
nomes_dep.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 120 entries, 0 to 119
Data columns (total 3 columns):
Deputado 120 non-null object
Valor 120 non-null object
porcentagem 120 non-null float64
dtypes: float64(1), object(2)
memory usage: 2.9+ KB
Deputado Valor porcentagem
0 ITAMAR BORGES 1,225,322.51 1.60
1 CARLAO PIGNATARI 1,205,708.42 1.57
2 CAMPOS MACHADO 1,155,406.50 1.51
3 ALENCAR SANTANA BRAGA 1,149,436.08 1.50
4 FELICIANO FILHO 1,134,941.68 1.48
“ Deputado”列中包含人员名称。 “ porcentagem”列中有这些人的支出占整个机构总数的百分比
我尝试使用altair制作水平条形图,在X轴上为“ porcentagem”列的值,在Y轴上为“ Deputado”列的名称:
alt.Chart(nomes_dep.reset_index().head(10), title="Deputados com maiores totais de despesas em %").mark_bar().encode(
x=alt.X("porcentagem:Q", axis=alt.Axis(title="Porcentagem", format="%s")),
y=alt.Y(
"Deputado:N",
sort=alt.SortField(field="Porcentagem", op="sum", order="descending"),
axis=alt.Axis(title="Deputados")
)
)
但是在jupyter实验室中,我收到了以下消息:
Javascript Error: t is undefined. This usually means there's a typo in your chart specification. See the JavaScript console for the full traceback.
请,有人知道我如何避免此错误?