英文:
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()
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论