Pandas 按条件取数据(在另外一个dataframe中的两列时间之间的数据)?

如果 df['Tool/Chamber']与dfevent['Tool/Chamber'] 相等,且 df[’Start time’]在dfevent[‘StartTime’],fevent[‘EndTime’]之间,则取出满足条件的df行。
每个tool/Chamber 每个月有大于2次事件PM, event1, event2 要分别去dfevent 里面取各自的startTime, EndTime 进行判断
dfevent:
Pandas 按条件取数据(在另外一个dataframe中的两列时间之间的数据)?

Tool/Chamber    Type    Step    StartTime    EndTime    Cost    PM Date    Tool/Chamber/Date

760 GTV417/PM-6 Mini 07_Season 2022-08-31 20:28:00 2022-09-01 01:16:00 4.800000 08-31 GTV417/PM-6 08-31

771 GTV417/PM-5 Full 07_Season 2022-09-04 11:03:00 2022-09-04 15:51:00 4.800000 09-04 GTV417/PM-5 09-04

782 GTV417/PM-1 Full 07_Season 2022-09-07 21:01:00 2022-09-08 15:05:00 18.066667 09-07 GTV417/PM-1 09-07

793 GTV417/PM-2 Full 07_Season 2022-09-09 09:28:00 2022-09-09 14:16:00 4.800000 09-09 GTV417/PM-2 09-09

804 GTV417/PM-3 Full 07_Season 2022-09-10 20:33:00 2022-09-11 01:00:00 4.450000 09-10 GTV417/PM-3 09-10

815 GTV417/PM-4 Full 07_Season 2022-09-19 11:18:00 2022-09-19 15:55:00 4.616667 09-19 GTV417/PM-4 09-19

826 GTV417/PM-5 Mini 07_Season 2022-09-25 23:57:00 2022-09-26 04:47:00 4.833333 09-25 GTV417/PM-5 09-25

837 GTV417/PM-6 Full 07_Season 2022-09-26 09:15:00 2022-09-26 16:03:00 6.800000 09-26 GTV417/PM-6 09-26

848 GTV417/PM-1 Mini 07_Season 2022-09-30 08:54:00 2022-09-30 13:39:00 4.750000 09-30 GTV417/PM-1 09-30

859 GTV417/PM-3 Mini 07_Season 2022-10-05 08:56:00 2022-10-05 13:43:00 4.783333 10-05 GTV417/PM-3 10-05

df:
Pandas 按条件取数据(在另外一个dataframe中的两列时间之间的数据)?

自己写的有点问题,丢了很多应该有的数据:

 dfevent.loc[:, ['StartTime', 'EndTime']] = dfevent[['StartTime', 'EndTime']].apply(pd.to_datetime)

df.loc[:, ['Start time', 'End time']] = df[['Start time', 'End time']].apply(pd.to_datetime)

df1 = dfevent.merge(df, on = 'Tool/Chamber',how ='right').drop_duplicates()#[['Tool/Chamber','Type','StartTime1','EndTime1']]

idx = df1[df1['Start time1'].between(df1['StartTime1'], df1['EndTime1'])].index

dfF = df1.iloc[idx,:]

以上是 Pandas 按条件取数据(在另外一个dataframe中的两列时间之间的数据)? 的全部内容, 来源链接: utcz.com/p/938640.html

回到顶部