Pandas DataFrame Calculate time difference between 2 columns on specific time range
I want to calculate time difference between two columns on specific time range.
I try df.between_time
but it only works on index.
Ex. Time range: between 18.00 - 8.00
Data :
start stop
0 2018-07-16 16:00:00 2018-07-16 20:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00
2 2018-07-13 17:54:00 2018-07-13 21:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00
4 2018-07-20 00:21:00 2018-07-20 04:21:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00
Expect Result :
start stop time_diff
0 2018-07-16 16:00:00 2018-07-16 20:00:00 02:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00 0
2 2018-07-13 17:54:00 2018-07-13 21:54:00 03:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00 0
4 2018-07-20 00:21:00 2018-07-20 04:21:00 04:00:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00 14:00:00
Note: If time_diff > 1 days, I already deal with that case.
Question: Should I build a function to do this or there are pandas build-in function to do this? Any help or guide would be appreciated.
python pandas datetime
|
show 3 more comments
I want to calculate time difference between two columns on specific time range.
I try df.between_time
but it only works on index.
Ex. Time range: between 18.00 - 8.00
Data :
start stop
0 2018-07-16 16:00:00 2018-07-16 20:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00
2 2018-07-13 17:54:00 2018-07-13 21:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00
4 2018-07-20 00:21:00 2018-07-20 04:21:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00
Expect Result :
start stop time_diff
0 2018-07-16 16:00:00 2018-07-16 20:00:00 02:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00 0
2 2018-07-13 17:54:00 2018-07-13 21:54:00 03:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00 0
4 2018-07-20 00:21:00 2018-07-20 04:21:00 04:00:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00 14:00:00
Note: If time_diff > 1 days, I already deal with that case.
Question: Should I build a function to do this or there are pandas build-in function to do this? Any help or guide would be appreciated.
python pandas datetime
What isdf.dtypes
?
– timgeb
Nov 12 at 7:49
1
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
1
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59
|
show 3 more comments
I want to calculate time difference between two columns on specific time range.
I try df.between_time
but it only works on index.
Ex. Time range: between 18.00 - 8.00
Data :
start stop
0 2018-07-16 16:00:00 2018-07-16 20:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00
2 2018-07-13 17:54:00 2018-07-13 21:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00
4 2018-07-20 00:21:00 2018-07-20 04:21:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00
Expect Result :
start stop time_diff
0 2018-07-16 16:00:00 2018-07-16 20:00:00 02:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00 0
2 2018-07-13 17:54:00 2018-07-13 21:54:00 03:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00 0
4 2018-07-20 00:21:00 2018-07-20 04:21:00 04:00:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00 14:00:00
Note: If time_diff > 1 days, I already deal with that case.
Question: Should I build a function to do this or there are pandas build-in function to do this? Any help or guide would be appreciated.
python pandas datetime
I want to calculate time difference between two columns on specific time range.
I try df.between_time
but it only works on index.
Ex. Time range: between 18.00 - 8.00
Data :
start stop
0 2018-07-16 16:00:00 2018-07-16 20:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00
2 2018-07-13 17:54:00 2018-07-13 21:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00
4 2018-07-20 00:21:00 2018-07-20 04:21:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00
Expect Result :
start stop time_diff
0 2018-07-16 16:00:00 2018-07-16 20:00:00 02:00:00
1 2018-07-11 08:03:00 2018-07-11 12:03:00 0
2 2018-07-13 17:54:00 2018-07-13 21:54:00 03:54:00
3 2018-07-14 13:09:00 2018-07-14 17:09:00 0
4 2018-07-20 00:21:00 2018-07-20 04:21:00 04:00:00
5 2018-07-20 17:00:00 2018-07-21 09:00:00 14:00:00
Note: If time_diff > 1 days, I already deal with that case.
Question: Should I build a function to do this or there are pandas build-in function to do this? Any help or guide would be appreciated.
python pandas datetime
python pandas datetime
edited Nov 12 at 9:18
asked Nov 12 at 7:43
yolox
438
438
What isdf.dtypes
?
– timgeb
Nov 12 at 7:49
1
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
1
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59
|
show 3 more comments
What isdf.dtypes
?
– timgeb
Nov 12 at 7:49
1
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
1
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59
What is
df.dtypes
?– timgeb
Nov 12 at 7:49
What is
df.dtypes
?– timgeb
Nov 12 at 7:49
1
1
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
1
1
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59
|
show 3 more comments
1 Answer
1
active
oldest
votes
I think this can be a solution
tmp = pd.DataFrame({'time1': pd.to_datetime(['2018-07-16 16:00:00', '2018-07-11 08:03:00',
'2018-07-13 17:54:00', '2018-07-14 13:09:00',
'2018-07-20 00:21:00', '2018-07-20 17:00:00']),
'time2': pd.to_datetime(['2018-07-16 20:00:00', '2018-07-11 12:03:00',
'2018-07-13 21:54:00', '2018-07-14 17:09:00',
'2018-07-20 04:21:00', '2018-07-21 09:00:00'])})
time1_date = tmp.time1.dt.date.astype(str)
tmp['rule18'], tmp['rule08'] = pd.to_datetime(time1_date + ' 18:00:00'), pd.to_datetime(time1_date + ' 08:00:00')
# if stop exceeds 18:00:00, compute time difference from this hour
tmp['time_diff_rule1'] = np.where(tmp.time2 > tmp.rule18, (tmp.time2 - tmp.rule18), (tmp.time2 - tmp.time1))
# rearrange the dataframe with your second rule
tmp['time_diff_rule2'] = np.where((tmp.time2 < tmp.rule18) & (tmp.time1 > tmp.rule08), 0, tmp['time_diff_rule1'])
time_diff_rule1 time_diff_rule2
0 02:00:00 02:00:00
1 04:00:00 00:00:00
2 03:54:00 03:54:00
3 04:00:00 00:00:00
4 04:00:00 04:00:00
5 15:00:00 15:00:00
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row ispd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is16:00:00
but withrule18
it becomes15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed08:00:00
it should be convert to08:00:00
. Thank you for providing the example dataframe.
– yolox
Nov 12 at 10:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257733%2fpandas-dataframe-calculate-time-difference-between-2-columns-on-specific-time-ra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this can be a solution
tmp = pd.DataFrame({'time1': pd.to_datetime(['2018-07-16 16:00:00', '2018-07-11 08:03:00',
'2018-07-13 17:54:00', '2018-07-14 13:09:00',
'2018-07-20 00:21:00', '2018-07-20 17:00:00']),
'time2': pd.to_datetime(['2018-07-16 20:00:00', '2018-07-11 12:03:00',
'2018-07-13 21:54:00', '2018-07-14 17:09:00',
'2018-07-20 04:21:00', '2018-07-21 09:00:00'])})
time1_date = tmp.time1.dt.date.astype(str)
tmp['rule18'], tmp['rule08'] = pd.to_datetime(time1_date + ' 18:00:00'), pd.to_datetime(time1_date + ' 08:00:00')
# if stop exceeds 18:00:00, compute time difference from this hour
tmp['time_diff_rule1'] = np.where(tmp.time2 > tmp.rule18, (tmp.time2 - tmp.rule18), (tmp.time2 - tmp.time1))
# rearrange the dataframe with your second rule
tmp['time_diff_rule2'] = np.where((tmp.time2 < tmp.rule18) & (tmp.time1 > tmp.rule08), 0, tmp['time_diff_rule1'])
time_diff_rule1 time_diff_rule2
0 02:00:00 02:00:00
1 04:00:00 00:00:00
2 03:54:00 03:54:00
3 04:00:00 00:00:00
4 04:00:00 04:00:00
5 15:00:00 15:00:00
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row ispd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is16:00:00
but withrule18
it becomes15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed08:00:00
it should be convert to08:00:00
. Thank you for providing the example dataframe.
– yolox
Nov 12 at 10:02
add a comment |
I think this can be a solution
tmp = pd.DataFrame({'time1': pd.to_datetime(['2018-07-16 16:00:00', '2018-07-11 08:03:00',
'2018-07-13 17:54:00', '2018-07-14 13:09:00',
'2018-07-20 00:21:00', '2018-07-20 17:00:00']),
'time2': pd.to_datetime(['2018-07-16 20:00:00', '2018-07-11 12:03:00',
'2018-07-13 21:54:00', '2018-07-14 17:09:00',
'2018-07-20 04:21:00', '2018-07-21 09:00:00'])})
time1_date = tmp.time1.dt.date.astype(str)
tmp['rule18'], tmp['rule08'] = pd.to_datetime(time1_date + ' 18:00:00'), pd.to_datetime(time1_date + ' 08:00:00')
# if stop exceeds 18:00:00, compute time difference from this hour
tmp['time_diff_rule1'] = np.where(tmp.time2 > tmp.rule18, (tmp.time2 - tmp.rule18), (tmp.time2 - tmp.time1))
# rearrange the dataframe with your second rule
tmp['time_diff_rule2'] = np.where((tmp.time2 < tmp.rule18) & (tmp.time1 > tmp.rule08), 0, tmp['time_diff_rule1'])
time_diff_rule1 time_diff_rule2
0 02:00:00 02:00:00
1 04:00:00 00:00:00
2 03:54:00 03:54:00
3 04:00:00 00:00:00
4 04:00:00 04:00:00
5 15:00:00 15:00:00
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row ispd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is16:00:00
but withrule18
it becomes15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed08:00:00
it should be convert to08:00:00
. Thank you for providing the example dataframe.
– yolox
Nov 12 at 10:02
add a comment |
I think this can be a solution
tmp = pd.DataFrame({'time1': pd.to_datetime(['2018-07-16 16:00:00', '2018-07-11 08:03:00',
'2018-07-13 17:54:00', '2018-07-14 13:09:00',
'2018-07-20 00:21:00', '2018-07-20 17:00:00']),
'time2': pd.to_datetime(['2018-07-16 20:00:00', '2018-07-11 12:03:00',
'2018-07-13 21:54:00', '2018-07-14 17:09:00',
'2018-07-20 04:21:00', '2018-07-21 09:00:00'])})
time1_date = tmp.time1.dt.date.astype(str)
tmp['rule18'], tmp['rule08'] = pd.to_datetime(time1_date + ' 18:00:00'), pd.to_datetime(time1_date + ' 08:00:00')
# if stop exceeds 18:00:00, compute time difference from this hour
tmp['time_diff_rule1'] = np.where(tmp.time2 > tmp.rule18, (tmp.time2 - tmp.rule18), (tmp.time2 - tmp.time1))
# rearrange the dataframe with your second rule
tmp['time_diff_rule2'] = np.where((tmp.time2 < tmp.rule18) & (tmp.time1 > tmp.rule08), 0, tmp['time_diff_rule1'])
time_diff_rule1 time_diff_rule2
0 02:00:00 02:00:00
1 04:00:00 00:00:00
2 03:54:00 03:54:00
3 04:00:00 00:00:00
4 04:00:00 04:00:00
5 15:00:00 15:00:00
I think this can be a solution
tmp = pd.DataFrame({'time1': pd.to_datetime(['2018-07-16 16:00:00', '2018-07-11 08:03:00',
'2018-07-13 17:54:00', '2018-07-14 13:09:00',
'2018-07-20 00:21:00', '2018-07-20 17:00:00']),
'time2': pd.to_datetime(['2018-07-16 20:00:00', '2018-07-11 12:03:00',
'2018-07-13 21:54:00', '2018-07-14 17:09:00',
'2018-07-20 04:21:00', '2018-07-21 09:00:00'])})
time1_date = tmp.time1.dt.date.astype(str)
tmp['rule18'], tmp['rule08'] = pd.to_datetime(time1_date + ' 18:00:00'), pd.to_datetime(time1_date + ' 08:00:00')
# if stop exceeds 18:00:00, compute time difference from this hour
tmp['time_diff_rule1'] = np.where(tmp.time2 > tmp.rule18, (tmp.time2 - tmp.rule18), (tmp.time2 - tmp.time1))
# rearrange the dataframe with your second rule
tmp['time_diff_rule2'] = np.where((tmp.time2 < tmp.rule18) & (tmp.time1 > tmp.rule08), 0, tmp['time_diff_rule1'])
time_diff_rule1 time_diff_rule2
0 02:00:00 02:00:00
1 04:00:00 00:00:00
2 03:54:00 03:54:00
3 04:00:00 00:00:00
4 04:00:00 04:00:00
5 15:00:00 15:00:00
answered Nov 12 at 8:38
J. Doe
935421
935421
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row ispd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is16:00:00
but withrule18
it becomes15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed08:00:00
it should be convert to08:00:00
. Thank you for providing the example dataframe.
– yolox
Nov 12 at 10:02
add a comment |
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row ispd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is16:00:00
but withrule18
it becomes15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed08:00:00
it should be convert to08:00:00
. Thank you for providing the example dataframe.
– yolox
Nov 12 at 10:02
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
Thanks for the answer but I think the last row should be 14:00:00.
– yolox
Nov 12 at 8:49
why do you think that ?
– J. Doe
Nov 12 at 9:09
why do you think that ?
– J. Doe
Nov 12 at 9:09
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
If it in my case I guess it should be like this pd.to_datetime('2018-07-21 08:00:00') - pd.to_datetime('2018-07-20 18:00:00') give 14:00:00
– yolox
Nov 12 at 9:19
in your example the last row is
pd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is 16:00:00
but with rule18
it becomes 15:00:00
– J. Doe
Nov 12 at 9:39
in your example the last row is
pd.to_datetime('2018-07-21 09:00:00') - pd.to_datetime('2018-07-20 17:00:00')
which is 16:00:00
but with rule18
it becomes 15:00:00
– J. Doe
Nov 12 at 9:39
because if time exceed
08:00:00
it should be convert to 08:00:00
. Thank you for providing the example dataframe.– yolox
Nov 12 at 10:02
because if time exceed
08:00:00
it should be convert to 08:00:00
. Thank you for providing the example dataframe.– yolox
Nov 12 at 10:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257733%2fpandas-dataframe-calculate-time-difference-between-2-columns-on-specific-time-ra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is
df.dtypes
?– timgeb
Nov 12 at 7:49
1
@timgeb I convert it to datetime by using pd.to_datetime
– yolox
Nov 12 at 7:51
1
Ok. I don't understand how you get to those expected valules. For example, the times in the first row are 4 hours apart, how do you get 2?
– timgeb
Nov 12 at 7:53
@timegeb if time exceeds 18.00 only use 18.00 to calculate. Sorry for not clear question.
– yolox
Nov 12 at 7:57
Ok and in the second row both times are between 8 and 18. Why is their difference 0?
– timgeb
Nov 12 at 7:59