question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to filter data based on date?

See original GitHub issue

This doesn’t seem to work:

from altair import *

Chart(Data(
    formatType='csv',
    url='http://vega.github.io/vega-lite/data/stocks.csv',
),
    description='Stock prices of 5 Tech Companies Over Time.',
).mark_line().encode(
    color='symbol:N',
    x='date:T',
    y='price:Q',
).transform_data(filter='datum.date < "2008-01-01"')

By the way the example on this page https://altair-viz.github.io/gallery/line_color.html is broken since ‘format’ is no longer a valid argument to ‘Data’

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Jan 17, 2021

As you’ve written it, none of the rows pass the filter because none of the timestamps are equal to the string '2000'. If you want to extract the year from a timestamp in a vega-lite filter expression, you can use vega expressions to do so. For example:

alt.Chart(pop).mark_area().encode(
    x='age:O',
    y='people:Q',
).transform_filter(
    'year(datum.year) == 2000'
)
0reactions
firasmcommented, Jan 17, 2021

thanks!! Vega expressions look very useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter by date - Excel formula - Exceljet
To filter data to include data based on dates, you can use the FILTER function with one of Excel's date functions. In the...
Read more >
How to Filter Date Range in Excel (5 Easy Methods)
Select any cells among B4 and D4 and then go to Home >> Sort & Filter >> Filter · After that, click on...
Read more >
How to Filter Data Based on Dates - MicroStrategy
Click Create on any page, and select New Filter. · In the pane on the left, navigate to the attribute with the date...
Read more >
Filter by date | Algolia
Dates aren't only useful for sorting. You can also leverage them to filter search results on a specific date range. Imagine you have...
Read more >
Excel Filter for Date Range 2 Ways - Contextures Blog
The first way to filter for a date range, is to use one of the Date Filter options. There are dynamic date range...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found