Skip to content
Advertisement

Tag: loops

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

Advertisement