不确定我的Altair代码在pandas可视化中有什么问题?

huangapple go评论92阅读模式
英文:

Not sure what is wrong with my Altair code for visualisation in pandas?

问题

I'm working through a tutorial on Altair in Python.

Loaded data fine.

  1. df = pd.read_csv("https://raw.githubusercontent.com/onlyphantom/miband/main/data/run_1km.csv", parse_dates=['startTime'])
  2. df['day_of_week'] = df['startTime'].dt.day_name()
  3. df.head()

Got my first plots such as

  1. alt.Chart(df).mark_point().encode(
  2. x="seconds_per_km",
  3. y="day_of_week",
  4. color="day_of_week"
  5. ).interactive()

But when I try to use

  1. alt.Chart(df).mark_point().encode(
  2. alt.x("seconds_per_km"),
  3. alt.y("day_of_week"),
  4. alt.color("day_of_week")
  5. ).interactive()

I get an error:

  1. AttributeError: module 'altair' has no attribute 'x'

Why? I'm running version 4.2.2.

英文:

I'm working through a tutorial on Altair in Python.

https://www.youtube.com/watch?v=umTwkgQoo_E

Loaded data fine.

  1. df = pd.read_csv("https://raw.githubusercontent.com/onlyphantom/miband/main/data/run_1km.csv", parse_dates=['startTime'])
  2. df['day_of_week'] = df['startTime'].dt.day_name()
  3. df.head()

Got my first plots such as
alt.Chart(df).mark_point().encode(
x = "seconds_per_km",
y = "day_of_week",
color ="day_of_week"
).interactive()
不确定我的Altair代码在pandas可视化中有什么问题?

But when I try to use

  1. alt.Chart(df).mark_point().encode(
  2. alt.x("seconds_per_km"),
  3. alt.y("day_of_week"),
  4. alt.color("day_of_week")
  5. ).interactive()
  6. I get an error:
  7. Cell In[37], line 2
  8. 1 alt.Chart(df).mark_point().encode(
  9. ----> 2 alt.x("seconds_per_km"),
  10. 3 alt.y("day_of_week"),
  11. 4 alt.color("day_of_week")
  12. 5 ).interactive()
  13. AttributeError: module 'altair' has no attribute 'x'

Why? I'm running version 4.2.2

答案1

得分: 1

使用大写的 alt.X,它会起作用。

英文:

Use upper case alt.X and it will work

huangapple
  • 本文由 发表于 2023年5月13日 21:13:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242916.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定