Reputation: 675
The Data:
I have a column of data with time in minutes.
data_df = [2000, 4000, 392, 600]
The Question:
How can I convert it into a week, day, hour and minute into a datetime format that pandas can deal with?
Example:
Assuming time = 0 corresponds to '01-Jan-2010 00:00', how to I convert 2000 minutes to 02-Jan-2010 09:20'.
Upvotes: 2
Views: 5437
Reputation: 394409
Construct a TimedeltaIndex
from that column and add to your initial date:
In [6]:
df['time'] = dt.datetime(2010,1,1) + pd.TimedeltaIndex(df['minutes'], unit='m')
df
Out[6]:
minutes time
0 2000 2010-01-02 09:20:00
1 4000 2010-01-03 18:40:00
2 392 2010-01-01 06:32:00
3 600 2010-01-01 10:00:00
Upvotes: 7