I have the following sample dataframe that has object ids and total hours. the decimal values are minutes converted into a fraction of an hour.
# +----+----+--------+
# |col1|total_hours |
# +----+-------------+
# |obj1| 48387.837 |
# |obj2| 45570.0201 |
# |obj3| 39339.669 |
# |obj4| 37673.235 |
# |obj5| 3576 |
# |obj6| 15287.9999 |
# +----+-------------+
I want to show the total hours in hours: minutes format.
desired output:
# +----+----+--------+
# |col1|total_hours |
# +----+-------------+
# |obj1| 48387:50 |
# |obj2| 45570:01 |
# |obj3| 39339:40 |
# |obj4| 37673:14 |
# |obj5| 3576:00 |
# |obj6| 15288:00 |
# +----+-------------+
in SQL I am able to do this with the following function :
hr = trunc(col1);
minutes = round(hr -trunc(hr)* 0.6, 2);
hours_minutes= trim(replace(to_char(hr + minutes ,'999999999990.90'),'.',':'));
How can this be done in Pyspark?