0

I have a pandas dataframe with a lot of timestamps:

|     |         ti_ms |
|-----+---------------+
|   0 | 1551398400000 |
|   1 | 1551398700000 |
|   2 | 1551399000000 |
|   3 | 1551399300000 |
|   4 | 1551399600000 |
|   5 | 1551399900000 |
|   6 | 1551400200000 |
|   7 | 1551400500000 |
|   8 | 1551400800000 |

The interval is always 3000 miliseconds (5 minutes). I want to check if there is a gap, that means if the interval sometimes is bigger than 3000 miliseconds.

I would solve it like this:

make a new column with the delta between two following rows like this:

df['delta'] = df['ti_ms'] - df['ti_ms'].shift(1)

Then check if there is a df['delta'] != 3000 (except for the first row) --> if No everything is ok.

This seems to me not elegant enough. Is there a better way to look for a gap in the timestamps ?

Egirus Ornila
  • 1,234
  • 4
  • 14
  • 39
  • 2
    Possible duplicate of [Calculating difference between two rows in Python / Pandas](https://stackoverflow.com/questions/13114512/calculating-difference-between-two-rows-in-python-pandas) – Amit Gupta Mar 04 '19 at 15:04

1 Answers1

1

df.diff() should do. axis = 0 for rows and axis = 1 for columns yo can define. for more reference check Pandas documentation

Amit Gupta
  • 2,698
  • 4
  • 24
  • 37