I have two types of CSV files, and I want to merge them together. To do that, I want to locate certain values in each row and remove them if they are there.
I tried using list.Index or list.Remove functions but I get an error when the values are not in the specific file.
For example, the two rows are (I cut the rest of the rows for better display):
CSV 1950 1300 1180 48 48 400 2 PASS 0 51:31.5
CSV 3270 2500 1950 1300 1180 48
I want to locate the cells with the values "3270" and "2500" so the two files will align... After that I want to remove the empty cells so again - they will align...
Can you please help me understand the way to do this?
thanks, Nimrod.
I would advice you to loop each value from the file and then put some conditions deleting the elements and then merge the values into a new output file
Step1 Reading the file
It's hard to tell exactly what you're hoping to accomplish, but I think this ought to get you started.
Output:
Make sure that you're not using list.remove while you're iterating over that same list, or you'll likely mess yourself up. My code above uses a safer strategy of copying the values that pass your
if
test (column is not one of your values that you want to get rid of) to a new list, then writing that new list to a new .csv file.Is this more or less what you're intending to do?
To get rid of blank cells, I presume you could add
''
toremove_me
.