Python Forum
Python VLookup? Lookup Table?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python VLookup? Lookup Table?
#1
Hi All... can someone tell me an easy/efficient way in Python to create a lookup table that acts like Excel? My options are unlimited, but I cannot find just what I am looking for. I have a GUI where someone scans in a Badge# and I am writing that to a text file with other data. I need to either create a lookup table to get the persons name so that when I write the data, it shows both.

Example:
Badge Input Scan: 8923468
Needs to become: 8923468 (John Smith)

I can fill a simple text file like:
8923468, John Smith
I just need to find the simplest method for accomplishing this task and how to search the name like a VLOOKUP would do. Thanks
Reply
#2
It looks like you need a database. A simple text file (in any format - csv, json, etc.) will work too, sort of (i.e. load the file in memory as a dict and the process the scans), but a simple database (even sqlite will do - support comes with python) will be much better.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Is this for during execution only or are you also asking about the equivalent of a spreadsheet that uses VLookup? For execution only you can use dictionaries. You could store the data as a CSV, as JSON or as XML and then build the dictionary from that. If you do that then a database might be easier overall.

So it depends on details not yet revealed. If there is more data (other fields, such as level of access) that is relevant then that makes a difference too. Of course, the stated requirements are simple enough that this sounds like a class assignment and if so then there are likely not much more about requirements.
Reply
#4
thanks all for the suggestions on this. I will probably try one of these methods. To answer your question Sam Hobbs... Yes, this is something to lookup during execution. I am using a Tkinter GUI, and when they scan their badge number, I want to lookup their name, store to a variable and write it to a text file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Vlookup function in Pyhton antozas 1 631 Oct-02-2023, 04:16 AM
Last Post: vikraman
  "Vlookup" in pandas dataframe doug2019 3 1,840 May-09-2022, 01:35 PM
Last Post: snippsat
  2-dataframe, datetime lookup problem Mark17 0 1,228 Jan-27-2022, 01:02 AM
Last Post: Mark17
  Can I replace IF statements with a key lookup ? jehoshua 3 2,473 Mar-05-2021, 10:24 PM
Last Post: jehoshua
  python 3 dns lookup private domain didact 1 2,544 Sep-19-2020, 06:01 PM
Last Post: bowlofred
  Partial key lookup in dictionary GaryNR 1 3,429 Jul-16-2020, 06:55 PM
Last Post: Gribouillis
  trying to do a vlookup in pandas eeps24 1 1,929 May-22-2020, 02:10 PM
Last Post: eeps24
  Encoding and mac-vendor-lookup library tuanjggaa 1 2,684 Mar-27-2020, 03:12 PM
Last Post: deanhystad
  How to apply VLookup formula jonzee 2 3,527 Jan-12-2020, 04:16 PM
Last Post: Clunk_Head
  Excel Lookup riteshprakash 0 1,753 Sep-11-2019, 12:43 PM
Last Post: riteshprakash

Forum Jump:

User Panel Messages

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