get distinct values from column python code example
Example 1: how to get distinct value in a column dataframe in python
df.column.unique()
Example 2: pandas unique values in column
df.name.unique()
Example 3: python list distinct
my_list = list(set(my_list))
Example 4: python extract values that have different values in a column
df = pd.DataFrame({'author':['a', 'a', 'b'], 'products':['sr1', 'sr2', 'sr2']})
group = df.groupby('author')
df2 = group.apply(lambda x: x['subreddit'].unique())
df2 = df2.apply(pd.Series)
Example 5: 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()