Git Product home page Git Product logo

a_pandas_ex_closest_neighbours's Introduction

Find the lower and upper neighbours in a pandas.Series

pip install a-pandas-ex-closest-neighbours
    Usage:

from a_pandas_ex_closest_neighbours import pd_add_closest_neighbours
import pandas as pd
from random import choice  # random dataframe
pd_add_closest_neighbours()
sizes = list(range(1, 100))
df = pd.DataFrame([choice(sizes) for x in range(1000)])
df.columns = ['num']



    df
Out[3]:
     num
0     17
1     32
2     17
3     90
4     76
..   ...
995   69
996   82
997   65
998   84
999   62
[1000 rows x 1 columns]


min_neighbours2, max_neighbours2 = df.num.s_find_closest_neighbours(value=72, convertdtypes=True,
                                                   accept_exact_match=False)
min_neighbours2
Out[8]:
    lower_index  lower_value
0            95           71
1           184           71
2           265           71
3           291           71
4           486           71
5           569           71
6           644           71
7           652           71
8           742           71
9           804           71
10          830           71
11          964           71

max_neighbours2
Out[9]:
    upper_index  upper_value
0            26           73
1            44           73
2           119           73
3           161           73
4           219           73
5           397           73
6           415           73
7           492           73
8           593           73
9           610           73
10          612           73
11          802           73







min_neighbours2, max_neighbours2 = df.num.s_find_closest_neighbours(value=72, convertdtypes=True,
                                                   accept_exact_match=True)

max_neighbours1
Out[4]:
    upper_index  upper_value
0           105           72
1           147           72
2           210           72
3           281           72
4           317           72
5           361           72
6           377           72
7           386           72
8           485           72
9           521           72
10          675           72
11          956           72
12          957           72
min_neighbours1

Out[5]:
    lower_index  lower_value
0           105           72
1           147           72
2           210           72
3           281           72
4           317           72
5           361           72
6           377           72
7           386           72
8           485           72
9           521           72
10          675           72
11          956           72
12          957           72


    Parameters:
        series:pd.Series
            Only pandas.Series
        value:Union[float,int]
            the value you want to have the closest neighbours from
        convertdtypes:bool
            converts string numbers to numbers
            (default=False)
        accept_exact_match:bool
            example:
            True: if you are passing 72, and 72 is in the Series, the minimum and maximum values will be all the same, that means: 72
            False: All cells with 72 are excluded, and you won't see 72 in the results
            (default=False)
    Returns:
        tuple

a_pandas_ex_closest_neighbours's People

Contributors

hansalemaos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.