如何在Pyspark的间隔日到第二次提取纳秒?

发布于 2025-02-06 18:32:35 字数 399 浏览 0 评论 0原文

def calculate_session_duration(df):
     newDf = df.groupBy("SessionId").agg((F.max("TimeGenerated") - F.min("TimeGenerated")).alias("TimeRange"))
     return df2

大家好,我在Pyspark中具有以下功能,时间戳之间的减法使我返回“间隔日至秒”数据类型。 我试图弄清楚如何从“时间范围”列中提取纳秒秒,这就是这样: 在这里输入图像描述

您有任何建议吗?

谢谢。

def calculate_session_duration(df):
     newDf = df.groupBy("SessionId").agg((F.max("TimeGenerated") - F.min("TimeGenerated")).alias("TimeRange"))
     return df2

Hi guys, i have the following function in PySpark, the subtraction between timestamp returns me an "interval day to seconds" data type.
I'm trying to figure it out how to extract the nanoseconds from the column "Time Range" that is something like this:
enter image description here

Do you have any suggestion?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有影子陪我不离不弃 2025-02-13 18:32:35

尝试以下操作:

def calculate_session_duration(df):
     newDf = df.groupBy("SessionId").agg((F.max("TimeGenerated").cast(DoubleType()) - F.min("TimeGenerated").cast(DoubleType())).alias("TimeRange"))
     return df2

输出将是这样的:

+-------------------+--------------------------+------------------+             
|x                  |y                         |TimeRange         |
+-------------------+--------------------------+------------------+
|2022-06-10 00:00:00|2022-06-10 17:26:39.438444|62799.438443899155|
+-------------------+--------------------------+------------------+

浮点之后的值是第二部分。

Try this:

def calculate_session_duration(df):
     newDf = df.groupBy("SessionId").agg((F.max("TimeGenerated").cast(DoubleType()) - F.min("TimeGenerated").cast(DoubleType())).alias("TimeRange"))
     return df2

The output will be something like this:

+-------------------+--------------------------+------------------+             
|x                  |y                         |TimeRange         |
+-------------------+--------------------------+------------------+
|2022-06-10 00:00:00|2022-06-10 17:26:39.438444|62799.438443899155|
+-------------------+--------------------------+------------------+

and values after the floating point are fractions of second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文