subset dataset with unique rows pandas code example
Example 1: dataframe python unique values rows
# get the unique values (rows)
df.drop_duplicates()
Example 2: python - subset dataframe based on unique value of a clumn
# Keep first duplicate value
my_df = my_df.drop_duplicates(subset=['my_var'])
# Keep last duplicate value
my_df = my_df.drop_duplicates(subset=['my_var'], keep='last')
# Remove all duplicate values
my_df = my_df.drop_duplicates(subset=['my_var'], keep=False)