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 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
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!
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
@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!