Skip to content

Idiomatic way to group time series data by week or month? #1484

Answered by saulpw
reagle asked this question in Q&A
Discussion options

You must be logged in to vote

For month, there are a few ways (assuming date column is named "d" and already converted to a date/time with @:

a) go to ColumnsSheet and set the fmtstr for "d" column to %Y-%m
or b) add a regex capture column with ;^(\d+-\d+)
or c) add a new f-string column: =f'{d.year}-{d.month:02}'

For week, I've used =d.isocalendar() which has year, week number, and weekday, and either expanded it out or added e.g [2] for a specific field (this is how the vdusage script discerns weekdays vs weekends). If you want the week number you could also use %Y-%W like in (a) above.

[These options aren't great, but they're only as bad as using regex or strftime or f-strings would be anyway.]

I'd love to figure o…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@geekscrapy
Comment options

@reagle
Comment options

@saulpw
Comment options

Answer selected by reagle
Comment options

You must be logged in to vote
2 replies
@saulpw
Comment options

@reagle
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants