Skip to content

Tag: pandas

How to remove empty rows in csv using pandas?

I got csv dataset like this and i need to remove any empty rows inside of it i already tried following code but still it fails when it reads empty row, and return pandas.errors.ParserError: Error tokenizing data. C error: Expected 7 fields in line 11, saw 8 sample dataset how can i remove those empty rows usi…

How to create a list from dataframe pandas

My dataset contains columns of usersID and itemsID that they have purchased. Each user might have purchased more than 1 item. I neeed to make a list so that the key will be the userID and the values the itemsID he purchased for example if user_1 has purchased [item_20,item_25,item_32], my dataset contains 3 r…

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 Se…

Delete duplicates if multiple fields follow conditions?

I had a simple Excel task to do today that I figured i’d use some Python to clean up. This led me to pandas and numpy.This is what i’d like to know if possible: I have these columns and about 5k rows: First Name | Last Name | Email | Address | City I want to remove duplicates that fall