Altair图表语法错误在简化中部署

发布于 2025-01-25 03:42:52 字数 958 浏览 2 评论 0原文

我在简化中遇到了令人发指的语法错误,我无法弄清楚。此代码工作完全很好,并显示图表:

ward_housing_cost = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N', axis=alt.Axis(format='d')),
 alt.Y('avg_housing_cost_ward:Q', title = 'rating of housing cost', 
 scale=alt.Scale(domain=(0, 5))
 ).properties(title = 'Rating of housing cost by ward')
st.altair_chart(ward_housing_cost)

...但是,此代码会遇到语法错误:

ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N'),
 alt.Y('avg_streets_sidewalks_ward:Q', title = 'rating of maintenance of 
 streets/sidewalks')
 ).properties(title = 'Rating of maintenance of streets/sidewalks by ward')
st.altair_chart(ward_streets_sidewalks)

这是错误的样子:

File "/app/shs2021/streamlit_app.py", line 90
  ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
                       ^
SyntaxError: invalid syntax

我尝试了所有我能想到的一切,包括从头开始重写事物,重命名图表,等等。

I'm getting an infuriating syntax error in streamlit that I can't figure out. This code works totally fine and displays the chart:

ward_housing_cost = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N', axis=alt.Axis(format='d')),
 alt.Y('avg_housing_cost_ward:Q', title = 'rating of housing cost', 
 scale=alt.Scale(domain=(0, 5))
 ).properties(title = 'Rating of housing cost by ward')
st.altair_chart(ward_housing_cost)

...but this one gets the syntax error:

ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N'),
 alt.Y('avg_streets_sidewalks_ward:Q', title = 'rating of maintenance of 
 streets/sidewalks')
 ).properties(title = 'Rating of maintenance of streets/sidewalks by ward')
st.altair_chart(ward_streets_sidewalks)

here is what the error looks like:

File "/app/shs2021/streamlit_app.py", line 90
  ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
                       ^
SyntaxError: invalid syntax

I have tried everything I can think of including rewriting the thing from scratch, renaming the chart, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2025-02-01 03:42:52

答案是:有一个语法错误,但它位于上面的代码块中,该错误是错误的。我没有意识到那是可能的。感谢@joelostblom的头脑。

The answer is: there WAS a syntax error, but it was in the block of code ABOVE where the error said it was. I didn't realize that was possible; thanks @joelostblom for the heads up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文