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 :: python array of tuples for loop 
Python :: django model different schema 
Python :: remove common rows in two dataframes pandas 
Python :: google sheet api python 
Python :: fill zeros left python 
Python :: python machine learning 
Python :: how to save frames in form of video in opencv python 
Python :: django on delete set default 
Python :: python bool 
Python :: max function python 
Python :: Converting (YYYY-MM-DD-HH:MM:SS) date time 
Python :: binary search recursive python 
Python :: validate longitude and latitude in python 
Python :: download youtube video 
Python :: how to multiply in python 
Python :: why pytest return No ModuleError 
Python :: matplotlib limit number of ticks 
Python :: how to print smallest number in python 
Python :: replace in lists python 
Python :: how to drop columns from pandas dataframe 
Python :: Python program to print positive numbers in a list 
Python :: django test imagefield 
Python :: render to response django 
Python :: creating numpy array using empty 
Python :: sum values in django models and insert value in model field 
Python :: how to change the size of datapoint in plot python 
Python :: plotly scatter facet change labels 
Python :: python flask rest api 
Python :: select dropdown lilst item in selenium 4 python 
Python :: how to plot a single cluster 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =