Reading, working with, and storing data from a csv table

Hello. I normally search for answers and try to figure out the problem, that is how I learn, but I can’t seem to figure out how to manipulate a csv table. I have figured out how to read a single line csv document but I have tried for 2 days and still can’t figure out a csv table. I’ll simplify my problem but the concept is still the same.

I have a csv document with 5 rows of data and 10 columns. I figured out how to load that csv table into a variable defined as an empty list (if that is the correct way?). The variable will show 5 elements when I check it so I believe it’s ok. But from there I want to do the following:

  1. Read each row and using a column (say the 10th index) to run an If-Then test against it to verify if it matches what I am looking for or tests against another regular variable.
  2. If that row does match then I want to store the entire row of data into a list so I can access it further in the rest of the program.

I have looked up articles on lists/tables but I guess I just can’t grasp the concept or understand what are the key elements of the coding. For example, let’s say the csv document is as follows:
1 aa bb cc dd ee ff gg hh ii
2 11 22 33 44 55 66 77 88 99
3 ab ac ad ae af ag ah ai aj
4 c1 c2 c3 c4 c5 c6 c7 c8 c9
5 zz yy xx ww vv uu tt ss rr
I want to test index 10 of each row, and extract the row of data containing ‘c9’ into a another global list. All the attempts I have tried keeps showing the row I extracted as a single element and not all 10 elements (actually my program has 17 columns). I’m not sure how to do a screen capture on here or I would post it. If anyone can point me to a page showing how to do this or provide a simple routine I will work on figuring it out. Thank you for any help.

Create a procedure like below. This will work only if no duplicates values exist at same index in each row

Thank you so much. So far this works perfectly. I was using the ‘For Each’ cycle to loop through the table list, which I figured out, but I couldn’t get the list pulled out into a another list to use in the program. I guess I was making it more difficult than what it is. Thanks again.

1 Like

I have another question that I am struggling on. I want to load the table into a variable and be able to access that variable at other parts of the program. But when I read the csv file and store it into a list variable, I keep getting errors that it is a list of length 0. How do you keep a table persistently stored in a variable throughout the program?

You could use tinyDB component

Thanks. I will try to work with that.