0

I would like to be able to find out what time it takes for the values in one column to change, based on when the value changes in another column. I have loaded an example of the table below.

| 23-02-03   12:01:27.213000 | 60   | 0  |
|  23-02-03 12:01:27.243000  | 60   | 0  |
|  23-02-03 12:01:27.313000  | 60   | 0  |
|  23-02-03 12:01:27.353000  | 50   | 0  |
|  23-02-03 12:01:27.413000  | 50   | 0  |
|  23-02-03 12:01:27.453000  | 50   | 0  |
|  23-02-03 12:01:27.513000  | 50   | 10 |
|  23-02-03 12:01:27.553000  | 50   | 10 |
|  23-02-03 12:01:27.613000  | 50   | 10 |
|  23-02-03 12:01:27.653000  | 50   | 10 |
|  23-02-03 12:01:27.713000  | 50   | 10 |
|  23-02-03 12:01:27.753000  | 50   | 10 |
|  23-02-03 12:01:27.813000  | 50   | 10 |
|  23-02-03 12:01:27.853000  | 49.5 | 10 |
|  23-02-03 12:01:27.913000  | 49.5 | 10 |
|  23-02-03 12:01:27.953000  | 49.5 | 10 |
|  23-02-03 12:01:28.013000  | 49.5 | 10 |
|  23-02-03 12:01:28.053000  | 49.5 | 10 |
|  23-02-03 12:01:28.113000  | 49.5 | 10 |
|  23-02-03 12:01:28.153000  | 49.5 | 10 |
|  23-02-03 12:01:28.213000  | 49.5 | 10 |
|  23-02-03 12:01:28.253000  | 49.5 | 25 |
|  23-02-03 12:01:28.313000  | 49.5 | 25 |
|  23-02-03 12:01:28.353000  | 49.5 | 25 |
|  23-02-03 12:01:28.423000  | 49.5 | 25 |
|  23-02-03 12:01:28.453000  | 48.3 | 25 |
|  23-02-03 12:01:28.533000  | 48.3 | 25 |
|  23-02-03 12:01:28.553000  | 48.3 | 25 |
|  23-02-03 12:01:28.634000  | 48.3 | 25 |
|  23-02-03 12:01:28.653000  | 48.3 | 25 |
|  23-02-03 12:01:28.743000  | 48.3 | 33 |
|  23-02-03 12:01:28.753000  | 48.3 | 33 |
|  23-02-03 12:01:28.843000  | 48.3 | 33 |
|  23-02-03 12:01:28.853000  | 48.3 | 33 |
|  23-02-03 12:01:28.943000  | 48.3 | 33 |
|  23-02-03 12:01:28.953000  | 48.3 | 33 |
|  23-02-03 12:01:29.043000  | 48.3 | 33 |
|  23-02-03 12:01:29.053000  | 48.3 | 33 |
|  23-02-03 12:01:29.143000  | 48.3 | 33 |
|  23-02-03 12:01:29.153000  | 48.3 | 33 |
|  23-02-03 12:01:29.243000  | 48.3 | 33 |
|  23-02-03 12:01:29.253000  | 48.3 | 33 |
|  23-02-03 12:01:29.343000  | 48.3 | 33 |
|  23-02-03 12:01:29.353000  | 49.1 | 33 |
|  23-02-03 12:01:29.443000  | 49.1 | 33 |
|  23-02-03 12:01:29.463000  | 49.1 | 33 |
|  23-02-03 12:01:29.543000  | 49.1 | 59 |
|  23-02-03 12:01:29.563000  | 49.1 | 59 |

So the first column is time stamp. When the value on column 1 changes from 50 to 49.5, the value in the third column changes a while after.

From this example col A changes from 60 to 50 at 27.353 col b changes from 0 to 10 at 27.513

So it takes .160 secs for the value in col b to change after the value changes in col a.

I would like to be able to use a python script to calculate this time difference, and also the average time difference.

I have just taken out the values to show below

| First Change             |      |    |
|--------------------------|------|----|
| 23-02-03 12:01:27.353000 | 50   |    |
| 23-02-03 12:01:27.513000 |      | 10 |
| Time diff                |      |    |
| 0.16                     |      |    |
| Second change            |      |    |
| 23-02-03 12:01:27.853000 | 49.5 |    |
| 23-02-03 12:01:28.253000 |      | 25 |
| Time diff                |      |    |
| 0.4                      |      |    |
| Third change             |      |    |
| 23-02-03 12:01:28.453000 | 48.3 |    |
| 23-02-03 12:01:28.743000 |      | 33 |
| Time diff                |      |    |
| 0.29                     |      |    |
| Fourth change            |      |    |
| 23-02-03 12:01:29.353000 | 49.1 |    |
| 23-02-03 12:01:29.543000 |      | 59 |
| 0.19                     |      |    |
| Average Time diff        |      |    |
| 0.26                     |      |    |

thanks

So, I have been able to get the differences by the following code

df['Change 1'] = df['Col1'].diff()
df['Change 2'] = df['Col2'].diff()

This stores when col1 changes and when col2 changes, as seen below. But I am not sure how to get the time diff when between them

| Datetime                   | Col1 | Col2 | Change 1 | Change 2 |
|----------------------------|------|------|----------|----------|
| 23-02-03   12:01:27.213000 |  60  |   0  | 0        | 0        |
| 23-02-03 12:01:27.243000   | 60   | 0    | 0        | 0        |
| 23-02-03 12:01:27.313000   | 60   | 0    | 0        | 0        |
| 23-02-03 12:01:27.353000   | 50   | 0    | 10       | 0        |
| 23-02-03 12:01:27.413000   | 50   | 0    | 0        | 0        |
| 23-02-03 12:01:27.453000   | 50   | 0    | 0        | 0        |
| 23-02-03 12:01:27.513000   | 50   | 10   | 0        | 10       |
| 23-02-03 12:01:27.553000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.613000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.653000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.713000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.753000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.813000   | 50   | 10   | 0        | 0        |
| 23-02-03 12:01:27.853000   | 49.5 | 10   | 0.5      | 0        |
| 23-02-03 12:01:27.913000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:27.953000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.013000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.053000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.113000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.153000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.213000   | 49.5 | 10   | 0        | 0        |
| 23-02-03 12:01:28.253000   | 49.5 | 25   | 0        | 15       |
| 23-02-03 12:01:28.313000   | 49.5 | 25   | 0        | 0        |
| 23-02-03 12:01:28.353000   | 49.5 | 25   | 0        | 0        |
| 23-02-03 12:01:28.423000   | 49.5 | 25   | 0        | 0        |
| 23-02-03 12:01:28.453000   | 48.3 | 25   | 1.2      | 0        |
| 23-02-03 12:01:28.533000   | 48.3 | 25   | 0        | 0        |
| 23-02-03 12:01:28.553000   | 48.3 | 25   | 0        | 0        |
| 23-02-03 12:01:28.634000   | 48.3 | 25   | 0        | 0        |
| 23-02-03 12:01:28.653000   | 48.3 | 25   | 0        | 0        |
| 23-02-03 12:01:28.743000   | 48.3 | 33   | 0        | 8        |
| 23-02-03 12:01:28.753000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:28.843000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:28.853000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:28.943000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:28.953000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.043000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.053000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.143000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.153000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.243000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.253000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.343000   | 48.3 | 33   | 0        | 0        |
| 23-02-03 12:01:29.353000   | 49.1 | 33   | 0.8      | 0        |
| 23-02-03 12:01:29.443000   | 49.1 | 33   | 0        | 0        |
| 23-02-03 12:01:29.463000   | 49.1 | 33   | 0        | 0        |
| 23-02-03 12:01:29.543000   | 49.1 | 59   | 0        | 26       |
| 23-02-03 12:01:29.563000   | 49.1 | 59   | 0        | 0        |

I've had an idea, if I was able to drop the values in-between then this might make it easier to check

thewal
  • 75
  • 6

0 Answers0