What is the mapping of index to day of the week with using Fast AI's datepart function? - fast-ai

What is the mapping of index to day of the week with using Fast AI's datepart function? It's not explained in the docs.
Code:
add_datepart(df, date_column)
https://docs.fast.ai/tabular.transform.html#add_datepart

Related

Spotfire change datetime column to monday of weekday

im using spotfire software and i have a datetime column like:
DateTime
21/07/2022 12:11:01
21/07/2022 14:32:01
04/12/2022 10:22:01
30/06/2022 16:22:01
how can i created a new calculated column where it instead changes the date to the monday of the week for all values?
many thanks
i can do this in power bi by dropping the time and using the function
Start of Week Monday = 'Data'[DateTime ]+1-WEEKDAY('Data'[DateTime ]-1)
this results in all the values changing to the monday of its given week/month/year
how can i do this in spotfire?
Assuming you have the following functions available to you: DateAdd, DayOfWeek (*)
You could try:
DateAdd("dd",1 - (If(DayOfWeek([original_Date])=0,7,DayOfWeek([original_Date]))),[original_Date])
This resets the date (including the time portion) to the previous Monday.
Initially I had tried the simpler formula:
DateAdd("dd",1 - DayOfWeek([original_Date]),[original_Date])
but Sunday is mapped to a zero, so whenever the original day was a Sunday, it was pushed to the following Monday.
It does depend on your original settings so you may have to play around with the numbers a bit.
(*) depending on what the source of your data is, equivalent functions may be available.

SQLite: Average grouped by hour

I have a dataset with Power measurements over several days. I want to find the average value grouped by hour, which sounds pretty straightforward, but I only get one result. I have tried the following (and several variations of this), and I am not sure what I'm missing. I'm using SQLite.
select AVG(Power)
from TrafoTotal
group by strftime('%H', Time);
Any help is greatly appreciated, thanks!
Probably strftime() returns null because the column Time contains datetime values that are not in the format YYYY-MM-DD hh:mm:ss which is the only valid datetime format for SQLite.
If this is the case then all your datetimes are considered as only 1 group and you get only 1 (wrong) average as result.
So change the format of your dates and your query will work.

int_months_between for weeks in impala?

What would be the best solution for int_months_betweenin weeks for Impala?
Would I have to work with Invervals or what is the best recommendation.
The easiest way would be to use datediff function, which returns difference in days, and then to divide the result with 7. It will not be precise in terms of business weeks, and there might be some ambiguous results at the beginning or end of the year, but in general it should do the trick. This is function signature for Impala 5.8.x:
datediff(timestamp enddate, timestamp startdate)

Date function in standard SQL in Google bigquery

What are the date functions like (YEAR(), MONTH(), DATEADD(), DATEDIFF(),...) in standard SQL of Goolge bigquery?
I used functions here when --use_legacy_sql is true, but they don't work with standard SQL.
You can find all Date functions for BigQuery Standard SQL here: https://cloud.google.com/bigquery/sql-reference/functions-and-operators#date-functions
Specifically EXTRACT returns the value corresponding to the specified date part. The part must be one of:
DAYOFWEEK (Returns 1-7, where 1=Sunday ... 7=Saturday)
DAY
DAYOFYEAR
MONTH
QUARTER (Returns 1-4)
YEAR
See also DATE_ADD, DATE_SUB, DATE_DIFF and rest for respectively DATEADD(), DATEDIFF() ...

PL/SQL group by week

In MySQL I am using
week(date,3)
to get correct values of week grouping.
How to translate this to PL/SQL? I'v tried the following but what about this 3 from week function in mysql?
TRUNC (created_dt, 'IW')
Oracle is using the NLS setting of the database to determinate how the week number should be calculated and therefor there is no need (according to Oracle) for the '3' part pf the MySQL function. I can image that there still should be useful to have this option but this is once again a sign of the fact that Oracle does not fully understand the needs of working outside USA.
Based on your MYSQL statment above, it returns the week of the specified date e.g. 2012-12-07, 3 as the second argument defines that the third day of the week is assumed as Monday...
If you look at this article it says there are 8 ways MYSQL WEEK() function can behave. So you gotta let us know what results you are trying to achieve by looking for MYSQL Week equivalent function in PL/SQL.
In most staright forward manner, MYSQL WEEK(date[mode]) returns the week number for a given date.
From re-reading your question, the only thing I grabbed that you want to achieve the first feature within PL/SQL and so you are looking for an equivalent function.
And with Oracle it gets slightly RAMEN...
W Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. It goes on with how the year starts. E.g. 2012 started on a Sunday, ORACLE THINKS.............. that weeks are Sundays to Saturday.
iw Week of year (1-52, 1-53) based on the ISO standard. Hence the weeks do not necessarily start on Sunday.
WW Week of the year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
By default Oracle NLS settings are set to following:
NLS_CALENDAR : Gregorian
NLS_DATE_LANGUAGE: AMERICAN
NLS_TERRITORY: AMERICA
So you can suggest Oracle to follow the calendar by manipulating your query level....
You could something like this:
select trunc('2012-12-07','YY') AS week_number,
to_number(to_char(trunc('2012-12-07','YY')+rownum-1,'D')) AS dayNumber_in_week
from dual connect by level <= 365
where to_char('2012-12-07','IW') = 3
and to_char('2012-12-07','DY') = 'MON';

Resources