I have the following dataframe in pyspark:
Name | Seconds
|Enviar solicitud ...| 1415
|Analizar mapa de ...| 1209|
|Modificar solicit...| 591|
|Entregar servicio...|91049|
I wish to convert the seconds column either to date or timestamp (hopefully todate), I am trying to use the following function
def to_date(seconds=0):
dat = ''
if seconds == 0:
dat = '0'
if (seconds / 86400) >= 1:
day = (int(seconds / 86400))
seconds = (seconds - 86400 * int(seconds / 86400))
dat = f'{day}d '
if (seconds / 3600) >= 1:
hour = (int(seconds / 3600))
seconds = (seconds - 3600 * int(seconds / 3600))
dat = dat + f'{hour}hr '
if (seconds / 60) >= 1:
minutes = (int(seconds / 60))
dat = dat + f'{minutes}min'
else:
return '0min'
return dat
But there is no easy way such as Pandas .apply(to_date) in pyspark, is there anyway to achieve what I am trying to do?
EXPECTED OUTPUT:
Analizar mapa de comparacion de presupuestos 1209 20min
Crear mapa de comparacion de presupuestos 12155 3hr 22min
Entregar servicios de bienes 91049 1d 1hr 17min