Skip to content
Advertisement

Tag: for-loop

How can I avoid for-loops using pandas?

Would love to know how to optimize this code without using for-loops, if it’s possible. What I’m trying to do is to categorize all the values in series df[‘Состояние’] looking at key words in lists list_rep and list_dem one by one. Thank you! Answer Use Series.str.lower fiirst, then Series.str.contains with join by | for regex OR and set new values

loop in a list of lists

I am trying to use two foor loops for a variable with that has list within a list, but this code doesn’t work. I get the error: list index out of range Answer In your loop, j is not an index, it’s the element, you can use range to loop over the indices (same thing about i, use i[j], not

Advertisement