df_extensions/space.py
def same_nearest_k(self, k: int = 5):
        """
        Expects the dataframe returned by `join_distance`.
        Groups by column 1, Expects first two columns to be id columns.
        Beyond that, will see if all columns (representing distances)
        have the same items
        in their lowest 'k' matches.
        Returns a column that can be averaged to get the overlap between
        two metrics.
        """
        df = self._obj

        def top_k(df, k=5):
            df = df.set_index(list(df.columns[:2])).rank()
            df = df <= k
            same_rank = df.sum(axis=1).reset_index(drop=True) == len(list(df.columns))
            data = [[same_rank.sum() / k]]
            d = pd.DataFrame(data, columns=[f"same_top_{k}"])
            return d.iloc[0]

        return df.groupby(df.columns[0]).apply(top_k, k=k).reset_index()

        Expects the dataframe returned by `join_distance`.
        Groups by column 1, Expects first two columns to be id columns.
        Beyond that, will see if all columns (representing distances)
        have the same items
        in their lowest 'k' matches.
        Returns a column that can be averaged to get the overlap between
        two metrics.
        
Expects the dataframe returned by `join_distance`.
Groups by column 1, Expects first two columns to be id columns.
Beyond that, will see if all columns (representing distances)
have the same items
in their lowest 'k' matches.
Returns a column that can be averaged to get the overlap between
two metrics.
Expects the dataframe returned by ` join_distance ` . Groups by column 1 Expects first two columns to be id columns . Beyond that will see if all columns ( representing distances ) have the same items in their lowest ' k ' matches . Returns a column that can be averaged to get the overlap between two metrics .
def same_nearest_k(self, k: int = 5):
        df = self._obj
        def top_k(df, k=5):
            df = df.set_index(list(df.columns[:2])).rank()
            df = df <= k
            same_rank = df.sum(axis=1).reset_index(drop=True) == len(list(df.columns))
            data = [[same_rank.sum() / k]]
            d = pd.DataFrame(data, columns=[f"same_top_{k}"])
            return d.iloc[0]
        return df.groupby(df.columns[0]).apply(top_k, k=k).reset_index()
def same_nearest_k ( self , k : int = 5 ) : df = self . _obj def top_k ( df , k = 5 ) : df = df . set_index ( list ( df . columns [ : 2 ] ) ) . rank ( ) df = df <= k same_rank = df . sum ( axis = 1 ) . reset_index ( drop = True ) == len ( list ( df . columns ) ) data = [ [ same_rank . sum ( ) / k ] ] d = pd . DataFrame ( data , columns = [ f"same_top_{k}" ] ) return d . iloc [ 0 ] return df . groupby ( df . columns [ 0 ] ) . apply ( top_k , k = k ) . reset_index ( )
Expects the dataframe returned by `join_distance`.
Expects the dataframe returned by ` join_distance ` .
"""
        Expects the dataframe returned by `join_distance`.
        Groups by column 1, Expects first two columns to be id columns.
        Beyond that, will see if all columns (representing distances)
        have the same items
        in their lowest 'k' matches.
        Returns a column that can be averaged to get the overlap between
        two metrics.
        """
self
k
int