简体   繁体   中英

Pandas Reordering Dataframe to Time Series

I have a dataframe with unlabeled columns with the following structure

0    101   100001   DT23    NaT   1900-01-01 20:00:00    DT24    1900-01-01 20:02:00 
1    101   100002   DT24    1900-01-01 20:02:00    1900-01-01 20:04:00     DT23   1900-01-01 20:05:05 
2    102   200001   DT23    NaT   1900-01-01 20:05:00    DT24    1900-01-01 20:07:00 
3    102   200002   DT24    1900-01-01 20:07:00    1900-01-01 20:09:00     DT23   1900-01-01 20:10:05 

I would like to shape the data to be different time series for each unique first column value. For "101" the data would be:

1900-01-01 20:00:00 DT23
1900-01-01 20:02:00 DT24
1900-01-01 20:04:00 DT24
1900-01-01 20:05:05 DT23

I have tried to iterate through the column for each unique value and append to a new series, but since the column names are not the same, I end up with a dataframe rather than a time series. How would I go about doing this? Thanks

If you are successfully ending with a DataFrame, then this answer can show you how to convert a DF to a time series

Convert Pandas dataframe to time series

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM