I have the following Pandas datetime-indexed dataframe:
date_time | category | num_files | num_lines | worst_index |
---|---|---|---|---|
2022-07-15 23:50:00 | black | 2 | 868 | 0.01 |
2022-07-15 23:50:00 | red | 5 | 5631 | 0.01 |
2022-07-15 23:50:00 | green | 1 | 1891 | 0.00 |
2022-07-15 23:50:00 | all | 8 | 8390 | 0.01 |
2022-07-16 00:00:00 | all | 0 | 0 | 0.00 |
2022-07-16 00:10:00 | all | 0 | 0 | 0.00 |
2022-07-16 00:20:00 | black | 1 | 656 | 0.00 |
2022-07-16 00:20:00 | red | 2 | 4922 | 0.00 |
2022-07-16 00:20:00 | green | 1 | 1847 | 0.00 |
2022-07-16 00:20:00 | all | 4 | 7425 | 0.00 |
2022-07-16 00:30:00 | all | 0 | 0 | 0.00 |
The data is collected every 10 minutes for the categories "black", "red" and "green" + there is a summary category "all" with respectively cumulated values for "num_files", "num_lines" and "worst_index".
In case, that num_files, num_lines or worst_index for the "all" category of a measurement point is 0 (zero), I would like to set those values for the three categories "black", "red" and "green" also to 0 (zero) in the dataframe. So, either insert a corresponding row if there is none for that timestamp so far.
Background is that I found the subsequently generated matplotlib graphs indicating wrongly for the three categories: e.g. for category "black" there should not be a direct line between timestamp "2022-07-15 23:50:00" "num_files"-value 2 and "num_files"-value 1 at timestamp "2022-07-16 00:20:00" as actually "num_files" for category black was 0 (zero) for the timestamps "2022-07-16 00:00:00" and "2022-07-16 00:10:00" in between but unfortunately the data is collected like this which I cannot change.
I tried to iterate through the datetime indexed dataframe using iterrows and to select / filter with loc but did not manage it with my too junior Python and Pandas knowledge and experience.