Add_datepart function

I am curious about these lines in the add_datepart function discussed in Lesson 1:

if isinstance(fld_dtype, pd.core.dtypes.dtypes.DatetimeTZDtype): 
  fld_dtype = np.datetime64

In this case, what exactly does the Elapsed filed represent?

df[targ_pre + 'Elapsed'] = fld.astype(np.int64) // 10 ** 9

1 Like

@number007 - Good question. The Elapsed field is the Unix timestamp, which is defined on Wikipedia as:

an approximation of the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970. Every day is treated as if it contains exactly 86400 seconds

This Stack Overflow answer does a good job showing how this conversion works.

Iā€™m not sure why the first two lines are needed. Perhaps someone else can help you with this.

1 Like