Python 熊猫错误“;只能比较标签相同的数据帧对象”;

Python 熊猫错误“;只能比较标签相同的数据帧对象”;,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,我有两个数据帧生成为 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=Fa

我有两个数据帧生成为

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
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
1 df2_t1[“交换比率”]=((df2_t1[“总资产负债表”][“第25页”]*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在新的_方法中(自我、其他)
62其他=来自zerodim(其他)的项目
63
--->64返回方法(自身、其他)
65
66返回新的_方法
/包装中的mnt/xarfuse/uid-115541/4cee94fa-ns-4026531840/pandas/core/ops/__init__u;.py(自身、其他)
519
520如果存在(其他,ABC系列)但不存在自索引(其他):
-->521 raise VALUE ERROR(“只能比较标记相同的系列对象”)
522
523左值=提取数组(self,提取数组=True)
ValueError:只能比较标签相同的系列对象
基本上,我想访问
df2_t1['pipeline_name']==df_prod_agg['pipeline_name']所在行的
['tot_map_comp_mins']['p25']


非常感谢您的帮助。

索引可能会出现以下问题:

你试过这个吗:

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

将输入和预期输出数据框添加为文本,以获得更好的响应。