Pandas错误"只能比较标签相同的DataFrame对象"



我有两个作为生成的数据帧

df_atn5_agg = df_atn5.groupby(['pipeline_name'], as_index=False).agg({'tot_map_comp_mins':['count', p25]})
df2_t1 = df_atn5_agg[df_atn5_agg['tot_map_comp_mins']['count'] > 1]
df_prod_agg = df_prod.groupby(['pipeline_name'], as_index=False).agg({'tot_map_comp_mins':['count', p25]})
df3_prod = df_prod_agg[df_prod_agg['tot_map_comp_mins']['count'] > 1]

我想在中添加一个新列

df2_t1['exchange_ratio'] = (
                            (df2_t1['tot_map_comp_mins']['p25']* 1.0) / 
                            ( 
                                df_prod_agg[df2_t1['pipeline_name'] == df_prod_agg['pipeline_name']]['tot_map_comp_mins']['p25']
                            )
                           )

我得到了这个

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-298-ddbc217187e3> in <module>
      1 df2_t1['exchange_ratio'] = ((df2_t1['tot_map_comp_mins']['p25']* 1.0) / 
      2                             ( 
----> 3                                 df_prod_agg[df2_t1['pipeline_name'] == df_prod_agg['pipeline_name']]
      4                                 ['tot_map_comp_mins']['p25']
      5                             )
/mnt/xarfuse/uid-115541/4cee94fa-ns-4026531840/pandas/core/ops/common.py in new_method(self, other)
     62         other = item_from_zerodim(other)
     63 
---> 64         return method(self, other)
     65 
     66     return new_method
/mnt/xarfuse/uid-115541/4cee94fa-ns-4026531840/pandas/core/ops/__init__.py in wrapper(self, other)
    519 
    520         if isinstance(other, ABCSeries) and not self._indexed_same(other):
--> 521             raise ValueError("Can only compare identically-labeled Series objects")
    522 
    523         lvalues = extract_array(self, extract_numpy=True)
ValueError: Can only compare identically-labeled Series objects

基本上我想访问df2_t1['pipeline_name'] == df_prod_agg['pipeline_name'] 所在行的df_prod_agg['tot_map_comp_mins']['p25']

非常感谢您的帮助。

中的索引可能存在问题:Pandas";只能比较相同标记的DataFrame对象";错误

你试过这个吗:

df2_t1['pipeline_name'].reset_index(drop=True) == df_prod_agg['pipeline_name'].reset_index(drop=True)

最新更新