Here I have a dataset with date, time and one input column. So here my time column is not good. So I want to give time range into that time column. So here first I did I just convert start time into 0 and convert whole time column into minutes.
Then next what I want to give time range like 0,60,120....
Mean what I expected output is:
first time convert
date time time
10/3/2018 6:15:00 0
10/3/2018 6:45:00 30
10/3/2018 7:45:00 90
10/3/2018 9:00:00 165.0
10/3/2018 9:25:00 190.0
10/3/2018 9:30:00 195.0
10/3/2018 11:00:00 285.0
10/3/2018 11:30:00 315.0
Expected output
time x3
0 7
30 5
60 0
120 0
165 7
180 0
190 7
195 5
240 0
285 7
300 0
315 7
So here you can see extra time added 60,120,180... for that x3 values are not available Then add 0 into x3 column
So here I just want to do is extra 60 min 60 min add to the time column
Here I wrote the code for convert time. But I don't know how to fill the extra 60 min into the time column.
My code:
data['date']= pd.to_datetime(data['date'] + " " + data['time'],
format='%d/%m/%Y %H:%M:%S', dayfirst=True)
lastday = data.loc[0, 'date']
def convert_time(x):
global lastday
if x.date() == lastday.date():
tm = x - lastday
return tm.total_seconds()/60
else:
lastday = x
return 0
data['time'] = data['date'].apply(convert_time)
Can anyone help me to solve this problem?
Subset of my csv:
date time X3
10/3/2018 6:15:00 7
10/3/2018 6:45:00 5
10/3/2018 7:45:00 7
10/3/2018 9:00:00 7
10/3/2018 9:25:00 7
10/3/2018 9:30:00 5
10/3/2018 11:00:00 7
10/3/2018 11:30:00 7
10/3/2018 13:30:00 7
10/3/2018 13:50:00 5
10/3/2018 15:00:00 7
10/3/2018 15:25:00 7
10/3/2018 16:25:00 7
10/3/2018 18:00:00 7
10/3/2018 19:00:00 5
My csv : enter link description here
for the reference:
expected time
0.0
30.0
60
90.0
120
165.0
180
190.0
195.0
240
285.0
300
315.0
360
420
435
455
480
525
540
550
:
:
:
:
0 new date ,start time=0
2
47
60
120
152
180