如何将时间戳字段拆分为年月日等?

How to split timestamp field into Year, Month and Day, etc?

我有一个具有以下定义的时间戳字段:

Time interval: the beginning of the time interval expressed as the number of millisecond elapsed from the Unix Epoch on January 1st, 1970 at UTC. The end of the time interval can be obtained by adding 600000 milliseconds (10 minutes) to this value. TYPE: numeric

我想将此字段拆分为年、月、日、星期几、周数。

看来我需要使用带公式的派生字段。但作为 SPSS 世界的新用户,我不清楚如何使用派生字段来执行此操作。

pandas中的等价物是:

df['Datetime'] = pd.to_datetime(df['Time interval'].astype(int))

df['Year'] = df['Datetime'].dt.year
df['Month'] = df['Datetime'].dt.month
df['Day'] = df['Datetime'].dt.day
df['DayOfWeek'] = df['Datetime'].dt.dayofweek

您要分别创建 5 个变量,对吗?

创建:

**1) Year - 使用派生节点并将新变量称为 'Year',语法为:"datetime_year(field)" -> 将提取数字中的年份 (2012)

2) Month- 使用派生节点并将新变量称为 'Month',语法为:"datetime_month(field)" -> 将提取数字中的月份(1 到 12)

3) Day of Month- 使用派生节点并将新变量称为 'DayMonth',语法为:"datetime_day(field)" -> 将提取数字中的月份日期(1 到 31 )

4) 星期几 - 使用派生节点并将新变量称为 'DayWeek',语法为:"datetime_weekday(field)" -> 将以数字(1 到 7)提取工作日

5) 周数 - 使用派生节点并将新变量称为 'WeekNumb',语法为:"date_iso_week(field)" -> ISO 8601(这是我从未在您的列表中使用过的唯一函数).**

此外,您可以在派生节点选项卡中检查其他表达式,只需 select 所有函数并进行一些测试。

IBM Ref

希望对您有所帮助。