[Python] Spark DataFrame TimestampType - how to get Year, Month, Day values from field?

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have Spark DataFrame with take(5) top rows as follows:

    import datetime

    [Row(date=datetime.datetime(1984, 1, 1, 0, 0), hour=1, value=638.55),
    Row(date=datetime.datetime(1984, 1, 1, 0, 0), hour=2, value=638.55),
    Row(date=datetime.datetime(1984, 1, 1, 0, 0), hour=3, value=638.55),
    Row(date=datetime.datetime(1984, 1, 1, 0, 0), hour=4, value=638.55),
    Row(date=datetime.datetime(1984, 1, 1, 0, 0), hour=5, value=638.55)]


    It's schema is defined as:

    elevDF.printSchema()

    root
    |-- date: timestamp (nullable = true)
    |-- hour: long (nullable = true)
    |-- value: double (nullable = true)


    How do I get the Year, Month, Day values from the 'date' field?

    Continue reading...

Compartilhe esta Página