I have a pandas timeseries such as:
df = pd.DataFrame(
{
"IDs": [
["A", "B"],
["A", "B", "A", "C"],
["A", "B", "A", "D", "C", "D"],
],
"distance": [[1], [1.1, 2.8], [1, 3, 0.5]],
},
index=[
pd.to_datetime("2022-01-01 12:00:00"),
pd.to_datetime("2022-01-01 12:00:01"),
pd.to_datetime("2022-01-01 12:00:02"),
],
)
This produces:
IDs distance
2022-01-01 12:00:00 [A, B] [1]
2022-01-01 12:00:01 [A, B, A, C] [1.1, 2.8]
2022-01-01 12:00:02 [A, B, A, D, C, D] [1, 3, 0.5]
And I would like to split the rows so that each row only contains the distance to a single pair such as:
IDs distance
2022-01-01 12:00:00 [A, B] 1.0
2022-01-01 12:00:01 [A, B] 1.1
2022-01-01 12:00:01 [A, C] 2.8
2022-01-01 12:00:02 [A, B] 1.0
2022-01-01 12:00:02 [A, D] 3.0
2022-01-01 12:00:02 [C, D] 0.5
What would be the best way to do this?
For information, each row IDs rows are always a list of 2n elements where n is the number of elements in the corresponding distance row.