dataframe unique values code example
Example 1: pandas unique values in column
df.name.unique()
Example 2: unique values in dataframe colume
df['Column_name'].value_counts()
Example 3: dataframe unique values in each column
for col in df:
print(df[col].unique())
Example 4: pandas distinct
>gapminder['continent'].unique()
array(['Asia', 'Europe', 'Africa', 'Americas', 'Oceania'], dtype=object)
Example 5: python - subset dataframe based on unique value of a clumn
my_df = my_df.drop_duplicates(subset=['my_var'])
my_df = my_df.drop_duplicates(subset=['my_var'], keep='last')
my_df = my_df.drop_duplicates(subset=['my_var'], keep=False)
Example 6: unique entries in column pandas
import pandas as pd
pd.set_option('display.max_row', 1000)
pd.set_option('display.max_columns', 50)
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [4, 24, 31, 2, 3]}
df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma'])
df
df.name.unique()