-
I could hammer something out with a complicated Python expression, but is there a more idiomatic way to take a date-type column and create a new one labeled by week or month? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I've been thinking of using the numeric binning option of the Freq Sheet that could do this for dates. I'd love the bin, to be able to take an input like, 1 hour bin, 2 hours, 3 days 1 month etc. |
Beta Was this translation helpful? Give feedback.
-
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 For week, I've used [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 out a nicer interface for dates. Currently |
Beta Was this translation helpful? Give feedback.
-
Thank you, I'm trying but not succeeding (such a newb!). I renamed the regex column BTW: If you have an expression column, how do you edit the expression that was used to create it? |
Beta Was this translation helpful? Give feedback.
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…