Reputation: 2978
I have pandas DataFrame like this:
import pandas as pd
d = {
'time': [0, 100, 200, 1400, 1500],
'value': [9, 8, 7, 6, 5],
'three': ['a', 'b', 'a', 'a', 'b']
}
df = pd.DataFrame(d)
How want to convert time
into hh:mm
format to get: 00:00
, 01:00
, 02:00
, etc.
How can I do it without if-then
?
Upvotes: 0
Views: 45
Reputation: 439
You need to convert it to string and perform a zfill()
and concatenate using':'
d['time'] = [str(a).zfill(4)[:2]+':'+str(a).zfill(4)[2:4] for a in d['time']]
Upvotes: 2