Python Forum
Trying to find an approximate match in a Column - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Trying to find an approximate match in a Column (/thread-4674.html)



Trying to find an approximate match in a Column - ankur2207 - Sep-02-2017

my question here
Hi everyone,

I've just started learning Python so no idea about 'how to find an approximate match of a value in Integer type of column'
my code here



RE: Trying to find an approximate match in a Column - Larz60+ - Sep-02-2017

Please read this
you need to give a lot more information on what you are trying to do!


RE: Trying to find an approximate match in a Column - ankur2207 - Sep-02-2017

Hi Sir,

So I have a column of integer values and generating random number. Now I need to find an exact or approximate match of that Random Number.

For Example:
Generated Random Number=55355
Exact match=55355
but when exact match is not in the data then we'll find approximate match and it can be 55280.

Kindly help me solving this and many thanks in advance.

Regards,
Ankur K


RE: Trying to find an approximate match in a Column - sparkz_alot - Sep-02-2017

If you are using v 3.5 +, you can try out math.isclose()


RE: Trying to find an approximate match in a Column - hbknjr - Sep-02-2017

math.isclose() can be helpful. It also lets you define the degree of approximation(relative and absolute tolerance).

(Sep-02-2017, 01:02 PM)ankur2207 Wrote: So I have a column of integer values and generating random number. Now I need to find an exact or approximate match of that Random Number.

But if you want to find the closest match in a list of the number then you can use:
closest = min(random_list, key=lambda x:abs(x-random_num))