Сопоставление соответствующих значений с соответствующими датами ⇐ Python
-
Anonymous
Сопоставление соответствующих значений с соответствующими датами
Input:
Id FirstDate LastDate values 1 2023-12-10 2023-12-14 2,4,6,7,8 2 2024-01-12 2023-12-21 0,0,16,2,7,0,1,1,2,3
Expected OutPut:
Id FirstDateAndLastDate value 1 2023-12-10 2 1 2023-12-11 4 1 2023-12-12 6 1 2023-12-13 7 1 2023-12-14 8 2 2024-01-12 0 2 2024-01-13 0 2 2024-01-14 16 2 2024-01-15 2 2 2024-01-16 7 2 2024-01-17 0 2 2024-01-18 1 2 2024-01-19 1 2 2024-01-20 2 2 2024-01-21 3
I am able to get dates as per expected but I am not able to map respective values in front of respective dates.
df.withColumn("FirstDateAndLastDate", explode(expr("sequence(to_date(FirstDate), to_date(LastDate), interval 1 day)")))
When I explode it separates the data in rows but not for respective dates.
df.withColumn("new_value", explode(split(col("values"), ",")))
Источник: https://stackoverflow.com/questions/778 ... tive-dates
Input:
Id FirstDate LastDate values 1 2023-12-10 2023-12-14 2,4,6,7,8 2 2024-01-12 2023-12-21 0,0,16,2,7,0,1,1,2,3
Expected OutPut:
Id FirstDateAndLastDate value 1 2023-12-10 2 1 2023-12-11 4 1 2023-12-12 6 1 2023-12-13 7 1 2023-12-14 8 2 2024-01-12 0 2 2024-01-13 0 2 2024-01-14 16 2 2024-01-15 2 2 2024-01-16 7 2 2024-01-17 0 2 2024-01-18 1 2 2024-01-19 1 2 2024-01-20 2 2 2024-01-21 3
I am able to get dates as per expected but I am not able to map respective values in front of respective dates.
df.withColumn("FirstDateAndLastDate", explode(expr("sequence(to_date(FirstDate), to_date(LastDate), interval 1 day)")))
When I explode it separates the data in rows but not for respective dates.
df.withColumn("new_value", explode(split(col("values"), ",")))
Источник: https://stackoverflow.com/questions/778 ... tive-dates