Q:

Change in DateTime returning 0 in pandas

My data looks like this:
01.02.2019 0:00

and it's format Date.Month.Year hours:minutes
When I'm trying to find change in time in minutes:
df['DateTime']=pd.to_datetime(df['DateTime'],infer_datetime_format=True,errors='coerce', format="%d.%m.%Y %H:%M")
df['dt'] = (df['DateTime']-df['DateTime'].shift(1)).astype('timedelta64[m]')

Pandas returns zero values:
0           NaN
1           0.0
2           0.0
3           0.0
4           0.0
            ... 
14022907    0.0
14022908    0.0
14022909    0.0
14022910    0.0
14022911    0.0
Name: dt, Length: 14022912, dtype: float64

I had similar data but with the format Date.Month.Year hours:minutes:seconds
I used the same approach but instead of minutes I was calculating seconds and it worked great:
df['DateTime']=pd.to_datetime(df['DateTime'],infer_datetime_format=True,errors='coerce', format="%d.%m.%Y %H:%M:%S")
df['dt'] = (df['DateTime']-df['DateTime'].shift(1)).astype('timedelta64[s]')

What could be causing the trouble in case with minutes?
Thanks!

A:

Probable Reason of problem:
Possibility is that maybe your DateTime column has same day, hour and minute information, resulting in 0 difference.
Check in between of dataframe and see if problem persists.

