Filter mutiple value in lists from Excel

Hi guys,!
I imported some data from Excel
and I need to filter strings (“Unknown”, “DEL”, “END”) from column B,D,E,I,J,M.
So in this set of data, I will only receive the data from row 2 & 4.

I have written a script but it seems the script is a bit long and complex.

Is there any way to improve this script ?
Thanks in advance.

fitler.dyn (66.5 KB)

@Trev Can you please share your excel file?

@Trev


You will need archilab but try something like this instead

1 Like

Sure! I forgot to upload it.
FILTER.xlsx (10.3 KB)

1 Like

I am not 100% sure if that what you are looking for but if you are simply looking for filtering the items you mentioned out, then this might work for you.

you can change the list o in the Undesireditems list to filter out more values. And after you can remove all the null values with list clean.

xlsList = IN[0]
undesiredItems = IN[1]

output = []
for list in xlsList:
	templist = []
	for item in list:
		if item not in undesiredItems:
			templist.append(item)
		
	output.append(templist)
	
	
OUT = output
1 Like

It’s perfect. That is certainly a much better way of doing it! Thanks so much!

Fitler_final.dyn (42.5 KB)

1 Like

I want to delete the whole row in the excel if it contains those strings.
I don’t know much about python, this script is for deleting the undesired cells in excel?
but it is useful!

1 Like

I am sorry I did not fully understand. Yes, that script deletes the undesired cells only.

This only deletes the whole row in case any of the undesired values appear.

fitler_01.dyn (15.0 KB)

2 Likes

Or here is another Python approach:
Filter.dyn (15.1 KB)

xlsList = IN[0]
undesiredItems = IN[1]

output = []

for list in xlsList:
	flag = True
	for item in undesiredItems:
		if item in list:
			flag = False
			break		
	if flag:
		output.append(list)
		
OUT = output
2 Likes

@AmolShah Do you have an idea how to skip the inner loop? I tried any() function but it is either I did not fully understand how to use it or it does not work as it is supposed to in Python 2.7

I tried sth like this but it does not work. I am curious about it!

   for list in xlsList:
	if any(undesiredItems) in list:
		output.append(list)

I am not sure I am getting this function correctly!

@mohamed.m.matook I don’t think you can use the any() function like that.
There must be a way to skip the inner loop or do a nested list comprehension but I’m not aware of it!