convert entire column with seconds to hours (pandas)

there is such a dataframe

      x     laikas_s
0   meh         5237
1   elec       20925

I want to get such a dataframe

      x     laikas_s
0   meh      1:27:17
1   elec     5:48:45

in python i would translate it like this

import datetime

sec = 20925


a = datetime.timedelta(seconds=sec)

print(a)

how to do it in Pandas?

Answer

You can use pd.to_timedelta() and specify the unit as second, as follows:

df['laikas_s'] = pd.to_timedelta(df['laikas_s'], unit='S')

Result:

print(df)

      x        laikas_s
0   meh 0 days 01:27:17
1  elec 0 days 05:48:45