Calculate a date difference between two dates in a series of a dataframe by ID?

Question:

Sorry if my question is simple i’m starting(so thank you for your help and understanding)
I am trying to get a date discrepancy by ‘identifier’ A B C D in the DF example. Using Python how can i add a column to establish the delta between each contract knowing that a person can have only one contract as he can have 10 or more. Thank you in advance.

header 1 header 2
cell 1 cell 2
cell 3 cell 4

I have try many things by DSS and Python but my result is false….

Asked By: YOUSSRA

||

Answers:

You mean something like:

df['new_col'] = df['header1'] - df['header2']

For timedeltas use:

import numpy as np
df['diff_days'] = (df['end_date'] - df['start_date']) / np.timedelta64(1, 'D')

D stands for timediffernce in days. Use "W", "M", "Y" for weeks, months or years.

Answered By: drevil
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.