Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

drop duplicate rows pandas except nan

df[(~df.duplicated()) | (df['col'].isnull())]
Comment

pandas remove duplicate rows least nan

# drop duplicate rows having the least null values
# (assuming 'col_1' is the column from which you want to remove the duplicates)

new_df = df.sort_values(by=list(df.columns), na_position='last').drop_duplicates('col_1', keep='first')
Comment

PREVIOUS NEXT
Code Example
Python :: pygame holding a button down 
Python :: python defaultdict 
Python :: how to write multi line lambda in python 
Python :: display video in jupyter notebook 
Python :: python program running time 
Python :: python bz2 install 
Python :: encryption python 
Python :: change case python 
Python :: how to output random letters in python 
Python :: python typed list 
Python :: python inf 
Python :: sys.executable 
Python :: Python - How To Ways to Remove xa0 From a String 
Python :: simple trivia question python 
Python :: array length godot 
Python :: localhost server in Python 
Python :: length of a matrix in python 
Python :: error urllib request no attribute 
Python :: python set recursion limit 
Python :: pandas dataframe scan column for values between numbers 
Python :: pyttsx3 install 
Python :: create virtual env 
Python :: completely uninstall python and all vritualenvs from mac 
Python :: how to count special values in data in python 
Python :: pandas replce none with nan 
Python :: python divide floor 
Python :: Python Tkinter timer animation 
Python :: dataframe summary pandas 
Python :: python pad with zeros 
Python :: how to do element wise multiplication in numpy 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =