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….
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.
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….
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.