I am trying to plot on Altair the following: x = daily time stamp y = count of records as the data is nominal not quantitative
when i try to aggregate x by month or quarters, is it possible to show y as the average count of records per day instead of the the sum?
chart = alt.Chart(data).mark_bar().encode(
x = alt.X('Date:T'),
y = alt.Y('count(Name):Q'),
color = alt.Color('descriptor:N')
)
chart
when i try to do
chart = alt.Chart(data).mark_bar().encode(
x = alt.X('month(Date):T'),
y = alt.Y('count(Name):Q'),
color = alt.Color('descriptor:N')
)
chart
it gets aggregated by total for the month, is it possible to do average of the count per month?
You can apply multiple aggregates using Altair's transform syntax. For your chart, you might do something like this:
alt.Chart(data).transform_aggregate(
daily_count = 'count(Name)',
groupby=['Date', 'descriptor']
).mark_bar().encode(
x = alt.X('month(Date):O'),
y = alt.Y('mean(daily_count):Q'),
color = alt.Color('descriptor:N')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With