Python beginner here.
I couldn't find anything similar to this, but I have the feeling it shouldn't be so hard.
I have a large excel sheet with values from different sensors, but some of the values are missing due to errors in the measurements. So when I put everything into a pandas dataframe I have something like this:
| TimeStamp1 | Sensor1 | TimeStamp2 | Sensor2 |
|---|---|---|---|
| 08:00 | 100 | 08:00 | 60 |
| 08:05 | 102 | 08:10 | 40 |
| 08:10 | 105 | 08:15 | 50 |
| 08:15 | 101 | 08:25 | 31 |
| 08:20 | 103 | NaT | NaN |
| 08:25 | 104 | NaT | NaN |
The real dataframe has 7 sensors and more than 100k rows, so there are different numbers of NaT's and NaN's in different columns.
I need timestamps for each sensor to be aligned in order to avoid some inconsistencies. So I want to shift the lines in TimeStamp2 and Sensor2 from the point where it differs from TimeStamp1, add the missing time and a NaN (or empty) value in the position in Sensor2, and make the NaT and NaN at the end disappear from both columns.
An output like this:
| TimeStamp1 | Sensor1 | TimeStamp2 | Sensor2 |
|---|---|---|---|
| 08:00 | 100 | 08:00 | 60 |
| 08:05 | 102 | 08:05 | Empty (NaN) |
| 08:10 | 105 | 08:10 | 40 |
| 08:15 | 101 | 08:15 | 50 |
| 08:20 | 103 | 08:20 | Empty (NaN) |
| 08:25 | 104 | 08:25 | 31 |
I guess I could simplify the question by asking a way to insert a specific element in a specific row of a specific column. All shifting examples I've seen will shift the entire column up or down. Is there an easy way to do this?
If it's easier, this solution also works for me:
| TimeStamp | Sensor1 | Sensor2 |
|---|---|---|
| 08:00 | 100 | 60 |
| 08:05 | 102 | Empty (NaN) |
| 08:10 | 105 | 40 |
| 08:15 | 101 | 50 |
| 08:20 | 103 | Empty (NaN) |
| 08:25 | 104 | 31 |
outeron it