Find the lower and upper neighbours in a pandas.Series
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file a_pandas_ex_closest_neighbours-0.10.tar.gz
.
File metadata
- Download URL: a_pandas_ex_closest_neighbours-0.10.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f11987ead5a093f12f95a0d849f25678100fc3c156dd414864fda589c8604b4b |
|
MD5 | 9f2f57e3c8cecd0106008ee614978362 |
|
BLAKE2b-256 | 451956818d1cba9ff52fc7aed568be8dfac213124bc24ba55efb86fd2ccb6186 |
File details
Details for the file a_pandas_ex_closest_neighbours-0.10-py3-none-any.whl
.
File metadata
- Download URL: a_pandas_ex_closest_neighbours-0.10-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31b49faec214708370d3d23bddf069bc08a84f34abd3edec872aff1b9104f4fe |
|
MD5 | 756490b0e7ec3b76029cd8469a535488 |
|
BLAKE2b-256 | b14c06586721d4cb7dc94f1bfd0eeea6f988ec063f04191dc140259d0123a773 |