I have two series namely x and y which were created by extracting the values related to a list of indices.
x:
Index | Timestamp |
---|---|
1 | 2022-11-16 13:00:00 |
143 | 2022-11-17 13:48:00 |
y:
Index | Timestamp |
---|---|
37 | 2022-11-16 19:13:00 |
157 | 2022-11-17 16:21:00 |
I want to combine these two series into a pandas dataframe. I used the following code for that.
x = pd.concat([Rising_Timestamp, Falling_Timestamp], ignore_index=True, axis=1)
But this creates Nan because of the indexes are different in the two series.
Preferred output:
start | End |
---|---|
2022-11-16 13:00:00 | 2022-11-16 19:13:00 |
2022-11-17 13:48:00 | 2022-11-17 16:21:00 |
How can I do this in pandas?
CodePudding user response:
x = x.reset_index(drop=True)
y = y.reset_index(drop=True)
df = pd.concat([x, y], axis=1)
Note that this will still produce NaN
values if the series aren't the same length. Also, it assumes that your data is aligned as you expect it to be.