Python Forum
Trying to find an approximate match in a Column
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to find an approximate match in a Column
#1
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
Reply
#2
Please read this
you need to give a lot more information on what you are trying to do!
Reply
#3
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
Reply
#4
If you are using v 3.5 +, you can try out math.isclose()
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 275 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Find factor to match test curve to golden curve SriRajesh 0 464 Jun-17-2021, 04:39 AM
Last Post: SriRajesh
  OpenPyxl: How to iterate through each Column (in 1 row) to find a value? chatguy 2 8,546 Apr-06-2021, 04:52 AM
Last Post: carlhyde
  find empty cells in a column Pedroski55 2 20,808 Sep-18-2017, 01:27 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020