I am struggling to get consistent datetime formatting out of a pandas array. I have a df with a calendar date colum of dtype datetime64[ns].
When I access the calendar date directly by iloc, say index 966, I get a Timestamp type
df.iloc[966]['Calendar Day']
Output 1:
Timestamp('1998-09-26 00:00:00')
However, when access the same line with a conditional statement, I get a different output format
a = df[ (df['colA'] == condA ) & (df['colB'] == condB ))]['Calendar Day']
a
results in output 2:
966 1998-09-26
Name: Calendar Day, dtype: datetime64[ns]
My condition is designed such that I can only report at most 1 line, or nan.
I am puzzled: The 2 statement look equal to me, given both times I access the same col of the same row of the same df, once by index, once by condition.
How do I make them equal? I would like to calculate a different, such as
abs( (a-b).days )
to get the relative time difference. That results in AttributeError: 'Series' object has no attribute 'days'
Thanks!