Selecting data from tables in a csv file

What options are there for selecting data from tables - so suppose I have this data in a CSV file:

Name Height Weight
Mike 180 70
Sam 160 60

and I want to find height of Mike or weight of Sam
Then I can load data into a table (list of lists) using listfromcsvtable, but I can’t use list lookupinpairs because this only works on pairs and there is also dictionary get-value-at-key-path but this also only works on pairs. So I can write my own function so something like:

And this works, but just wondering if there is a better way to do this where you either pass the index (as above) of the data you want or the column heading. The above could easily be amended to pass the index of the key, rather than hard-coding as index 1, but in my case I think all my data has the key as the first column.
The other alternative is to structure the data differently so like this:


So then I can use lookupinpairs like this:

or I can use a dictionary if I structure my data this way, but to structure my data like this using lists or dictionaries, then I can’t use listfromcsvtable and I would have to write my own procedure to load the data.
I looked at DataFile but that doesn’t seem to provide anything useful for selecting data.
So comments welcome if there are better ways to get data from tables.

There are many different ways of doing what you want, including your example. Here is another:

With the data coming from csv, it is easiest to use indexes to pull out the values.

If your data was in a json, then you could use dictionary blocks to achieve much the same thing:

{
"Mike":{"Height":180,"Weight":70},
"Sam":{"Height":160,"Weight":60}
}

Thanks for reply:
Your example seems to be the exact same algorithm:
Loop through list of lists (table) to find where first item of sublist = key:
Mine:

Yours;

Then select index required from subllist:
Mine:

image

Yours:

image

But is the dictionary method any better - how would that work?
My data is in CSV format with about 250 rows but I could easily convert this to JSON format so that AI2 loads a JSON file instead of a CSV file, but does this help - does this make it easier to load the file into a dictionary (I have not used JSON files before in AI2) so then I guess you would use something similar to my lookupinpairs example so something like:

With dictionaries

Thanks - that gives another method - not sure if this is any better - function would then be:

So here:
make new filtered list creates a list of rows for required key

I then select the first item in this list (this is the only item as my keys are unique)

I then select the index I want

Ah - I see now - a dictionary is natively in JSON format so I can just read it straight into a dictionary, so if I have file names.json:

{
"Mike":{"Height":180,"Weight":70},
"Sam":{"Height":160,"Weight":60}
}
Then I can do this:

This also works:
File names2.json:

{
"Mike":[180,70],
"Sam":[160,60]
}

with code:

The differentiating attributes for the two designs are uniqueness and sort order.

If you want to maintain a set sort order, beware of dictionary keys, sorted by the dictionary mechanism for its own eficiency.

If you need uniqueness, that's a good place to use dictionaries.
People names are never unique.

In either event, you still need to check for missing values. Filters can return empty lists, so have that Is List Empty block handy before jumping into a List Select.

You could always convert your csv into an sqlite table, then query the table for output:

SimpleSqlite used for the extension

(because of the unique id, you can have multiple "same names", but i have not handled this in the blocks, it returns the height and weight for the first same name found)