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

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

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.

df = pd.read_csv("https://raw.githubusercontent.com/onlyphantom/miband/main/data/run_1km.csv", parse_dates=['startTime'])
df['day_of_week'] = df['startTime'].dt.day_name()
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()

But when I try to use

alt.Chart(df).mark_point().encode(
    alt.x("seconds_per_km"),
    alt.y("day_of_week"),
    alt.color("day_of_week")
).interactive()

I get an error:

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.

df = pd.read_csv("https://raw.githubusercontent.com/onlyphantom/miband/main/data/run_1km.csv", parse_dates=['startTime'])
df['day_of_week'] = df['startTime'].dt.day_name()
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

alt.Chart(df).mark_point().encode(
    alt.x("seconds_per_km"),
    alt.y("day_of_week"),
    alt.color("day_of_week")
).interactive()

I get an error:

Cell In[37], line 2
      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()

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:

确定