why I have negative date by subtraction of two column?

2024/10/5 19:36:03

I'm trying to create a column his values is the subtraction of two column but I found strange values:

 Patient["Waiting"] = Patient["Appointment"] - Patient["Scheduled"]Scheduled                   Appointment       Waiting2016-04-29 18:38:08         2016-04-29        -1 days +05:21:52

I wonder why these negative values appear ??

Answer

@cᴏʟᴅsᴘᴇᴇᴅ explain it better:

When two datetime objects are subtracted, the result is a timedelta. Depending on which date was larger, the result could be positive or negative.

Also if all values in column have no times, in pandas are not shown.

Patient["Waiting"] = Patient["Appointment"] - Patient["Scheduled"]2016-04-29 00:00:00    - 2016-04-29 18:38:08 

For remove negative timedelatas is possible use abs:

Patient["Waiting"] = (Patient["Appointment"] - Patient["Scheduled"]).abs()
https://en.xdnf.cn/q/120264.html

Related Q&A

Python 3: AttributeError: int object has no attribute choice [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Scraping web pages with Python vs PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

error switching to iframe selenium python

Currently Im attempting to switch to iframe/fancybox, but im getting the following error:line 237, in check_response raise exception_class (message, screen, stacktrace) selenium.common.exceptions.WebDr…

SQL Date Variables in Python

I am writing a query inside a Python script.The query is as follows:cur = conn.cursor() query1 = """select max(date_time) from tablename""" cur.execute(queryy1) conn.commi…

Truble to create a matrix for sudoku in python

I have to make a sudoku template, so I need to get random numbers into the matrix, but they can not be repeated in the rows or columns, but I can not do it. For this I can not use numpy. In this case I…

Password validation in python with regex without duplicate chars

The parameter is a string. Check whether it forms a secure password.A password is safe ifthere is at least a lowercase letter in it, and there is at least one capital letter in it, and there is at leas…

Processing non-english text

I have a python file that reads a file given by the user, processes it, and ask questions in flash card format. The program works fine with an english txt file but I encounter errors when trying to pro…

Downloading all zip files from url

I need to download all the zip files from the url: https://www.ercot.com

sql to query set

I have 2 tables:puzz_meeting_candidats :- id, canceled, candidat_id, meeting_id puzz_meeting :- id, ClientI have a query follow: SELECT U1.`candidat_id` AS Col1 FROM `puzz_meeting_candidats` U1 INN…