df_extensions/space.py
def match_distance(self):
        """
        add a match percentage column where the tenth most distance is a 0% match
        and 0 distance is an 100% match.
        """
        df = self._obj

        def standardise_distance(df):
            df = df.copy()
            # use tenth from last because the last point might be an extreme outlier (in this case london)
            tenth_from_last_score = df["distance"].sort_values().tail(10).iloc[0]
            df["match"] = 1 - (df["distance"] / tenth_from_last_score)
            df["match"] = df["match"].round(3) * 100
            df["match"] = df["match"].apply(lambda x: x if x > 0 else 0)
            df = df.sort_values("match", ascending=False)
            return df

        return (
            df.groupby(df.columns[0], as_index=False)
            .apply(standardise_distance)
            .reset_index(drop=True)
        )

        add a match percentage column where the tenth most distance is a 0% match
        and 0 distance is an 100% match.
        
add a match percentage column where the tenth most distance is a 0% match
and 0 distance is an 100% match.
add a match percentage column where the tenth most distance is a 0% match and 0 distance is an 100% match .
def match_distance(self):
        df = self._obj
        def standardise_distance(df):
            df = df.copy()
            tenth_from_last_score = df["distance"].sort_values().tail(10).iloc[0]
            df["match"] = 1 - (df["distance"] / tenth_from_last_score)
            df["match"] = df["match"].round(3) * 100
            df["match"] = df["match"].apply(lambda x: x if x > 0 else 0)
            df = df.sort_values("match", ascending=False)
            return df
        return (
            df.groupby(df.columns[0], as_index=False)
            .apply(standardise_distance)
            .reset_index(drop=True)
        )
def match_distance ( self ) : df = self . _obj def standardise_distance ( df ) : df = df . copy ( ) tenth_from_last_score = df [ "distance" ] . sort_values ( ) . tail ( 10 ) . iloc [ 0 ] df [ "match" ] = 1 - ( df [ "distance" ] / tenth_from_last_score ) df [ "match" ] = df [ "match" ] . round ( 3 ) * 100 df [ "match" ] = df [ "match" ] . apply ( lambda x : x if x > 0 else 0 ) df = df . sort_values ( "match" , ascending = False ) return df return ( df . groupby ( df . columns [ 0 ] , as_index = False ) . apply ( standardise_distance ) . reset_index ( drop = True ) )
add a match percentage column where the tenth most distance is a 0% match
and 0 distance is an 100% match.
add a match percentage column where the tenth most distance is a 0% match and 0 distance is an 100% match .
"""
        add a match percentage column where the tenth most distance is a 0% match
        and 0 distance is an 100% match.
        """ # use tenth from last because the last point might be an extreme outlier (in this case london)
self