0

I have 2 dataframes generated as

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]

I wanted to add a new column to

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']
                            )
                           )

And I get this

---------------------------------------------------------------------------
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

Basically I want to access ['tot_map_comp_mins']['p25'] of df_prod_agg of the row where df2_t1['pipeline_name'] == df_prod_agg['pipeline_name']

Any help is much appreciated.

89f3a1c
  • 1,430
  • 1
  • 14
  • 24
Atanu
  • 61
  • 2
  • 12

1 Answers1

0

It could a problem with index like in: Pandas "Can only compare identically-labeled DataFrame objects" error

Have you tried this:

df2_t1['pipeline_name'].reset_index(drop=True) == df_prod_agg['pipeline_name'].reset_index(drop=True)
ThomaS
  • 815
  • 4
  • 13