Home > Blockchain >  ValueError: cannot join with no overlapping index names on the same dataframe
ValueError: cannot join with no overlapping index names on the same dataframe

Time:12-18

I am encountering a strange problem with a pandas dataframe where in, where() fails complaining that it cannot join on the overlapping index names.

ValueError: cannot join with no overlapping index names 

>>> feed_tail
             Close
           ABAN.NS ADFFOODS.NS AGARIND.NS AMRUTANJAN.NS ASAHIINDIA.NS
Date
2022-10-13   50.55      699.00     687.50        713.80        622.30
2022-10-14   52.00      709.05     672.85        712.90        609.20
2022-10-17   50.75      711.95     669.25        710.05        611.10
2022-10-18   50.90      730.85     680.25        707.95        609.85
2022-10-19   50.05      713.10     692.10        705.45        604.45
>>> feed_tail.columns
MultiIndex([('Close',       'ABAN.NS'),
            ('Close',   'ADFFOODS.NS'),
            ('Close',    'AGARIND.NS'),
            ('Close', 'AMRUTANJAN.NS'),
            ('Close', 'ASAHIINDIA.NS')],
           )
>>> feed_tail.index
DatetimeIndex(['2022-10-13', '2022-10-14', '2022-10-17', '2022-10-18',
               '2022-10-19'],
              dtype='datetime64[ns]', name='Date', freq=None)


>>> feed_tail['Close'] > 500
            ABAN.NS  ADFFOODS.NS  AGARIND.NS  AMRUTANJAN.NS  ASAHIINDIA.NS
Date
2022-10-13    False         True        True           True           True
2022-10-14    False         True        True           True           True
2022-10-17    False         True        True           True           True
2022-10-18    False         True        True           True           True
2022-10-19    False         True        True           True           True
>>> feed_tail.where(feed_tail['Close'] > 500)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...
  File "lib/python3.9/site-packages/pandas/core/indexes/base.py", line 4658, in join
    return self._join_multi(other, how=how)
  File "lib/python3.9/site-packages/pandas/core/indexes/base.py", line 4782, in _join_multi
    raise ValueError("cannot join with no overlapping index names")
ValueError: cannot join with no overlapping index names

I am not sure what diagnosis this dataframe needs. Any help here is sincerely appreciated.

CodePudding user response:

Maybe it causes by the multi-level column as the where() method expects a single-level column. Try to flatten it first.

filtered_df = feed_tail.reset_index().where(feed_tail['Close'] > 500)

CodePudding user response:

Where method accept a list like argument with boolean values for filtering. You must pass to it a pandas series, numpy array, python list, etc. But you pass to it a dataframe (df['close']>500) and where method raise error You can read pandas docs for more information about it

  • Related