Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将一列的分组最小值与表中的一组时间戳进行比较_Python_Pandas_Pandas Groupby - Fatal编程技术网

Python 将一列的分组最小值与表中的一组时间戳进行比较

Python 将一列的分组最小值与表中的一组时间戳进行比较,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,我有以下数据帧(仅为id3的一个值提取): 我尝试按id3分组,选择max_ts列的最小值,然后将其与每组id3和k的max_ts_fs进行比较。根据结果,我想添加一个布尔值作为单独的列 我试图做到以下几点: joined_h_raw_fs['new_col'] = np.where(joined_h_raw_fs.groupby(['id3'])['max_snsr_ts'].min().min() > joined_h_raw_fs.groupby(['id3', 'k'])['max

我有以下数据帧(仅为id3的一个值提取):

我尝试按id3分组,选择max_ts列的最小值,然后将其与每组id3和k的max_ts_fs进行比较。根据结果,我想添加一个布尔值作为单独的列

我试图做到以下几点:

joined_h_raw_fs['new_col'] = np.where(joined_h_raw_fs.groupby(['id3'])['max_snsr_ts'].min().min() > joined_h_raw_fs.groupby(['id3', 'k'])['max_ts_fs'] , True, False)
期望得到:

id1 id2 id3 id4 id5 id6 status  id7 max_snsr_ts max_ts_fs   k   new_col
292 346 1041    656 578 5780    on  53  10/21/2020 23:59    10/22/2020 23:30    48  FALSE
292 346 1041    657 708 7080    on  53  10/21/2020 23:59    10/22/2020 23:30    48  FALSE
292 346 1041    658 579 5790    on  53  10/19/2020 23:59    10/22/2020 23:30    48  FALSE
292 346 1041    657 708 5780    on  53  10/21/2020 23:59    10/23/2020 23:30    96  FALSE
292 346 1041    658 579 7080    on  53  10/19/2020 23:59    10/23/2020 23:30    96  FALSE
292 346 1041    656 578 5790    on  53  10/21/2020 23:59    10/23/2020 23:30    96  FALSE
但我得到了以下错误:

... last 1 frames repeated, from the frame below ...

pandas/_libs/tslibs/c_timestamp.pyx in pandas._libs.tslibs.c_timestamp._Timestamp.__richcmp__()

RecursionError: maximum recursion depth exceeded in comparison
我还是不太擅长熊猫,因为我正在从dplyr过渡

有人能指出我做错了什么吗


BR

如果需要,比较原始列用于具有相同大小的序列,如原始列由聚合值填充,也可以是
np。此处不需要使用

s1 = joined_h_raw_fs.groupby(['id3'])['max_snsr_ts'].transform('min')
s2 = joined_h_raw_fs.groupby(['id3', 'k'])['max_ts_fs'].transform('min') 
joined_h_raw_fs['new_col'] = s1 > s2
s1 = joined_h_raw_fs.groupby(['id3'])['max_snsr_ts'].transform('min')
s2 = joined_h_raw_fs.groupby(['id3', 'k'])['max_ts_fs'].transform('min') 
joined_h_raw_fs['new_col'] = s1 > s2