简体   繁体   中英

Pandas time series resample

I have a data frame with a datetime stamp column and a value column

datetime                 value
-------------------------------
2014-02-21 17:16:42        1
2014-02-21 17:46:00        2
2014-02-21 19:06:03        2
2014-02-22 03:16:42        4

and I'd like to replace the datetime column with a different datetime column that has additional values in it, and obtain something like this

datetime                 value
-------------------------------
2014-02-21 17:16:42        1
2014-02-21 17:20:00       
2014-02-21 17:46:00        2
2014-02-21 19:06:03        2
2014-02-22 00:06:42       
2014-02-22 03:16:42        4

(Maybe with NaN or something similar in the empty value positions)

I know this isn't resampling, but I didn't know what to call it. Is there a way to do that? Thanks a lot.

As simple as:

df = df[new_index]

Sweet, eah?

Values in new_index which do not appear in df.index will get a NaN value.

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