Dapatkan daftar nilai unik di kolom panda
a = df['column name'].unique() #returns a list of unique values
TheRubberDucky
a = df['column name'].unique() #returns a list of unique values
for col in df:
print(df[col].unique())
df = df.groupby('domain')['ID'].nunique()
print (df)
domain
'facebook.com' 1
'google.com' 1
'twitter.com' 2
'vk.com' 3
Name: ID, dtype: int64
# import pandas library
import pandas as pd
# create pandas DataFrame
df = pd.DataFrame({'fruits': ['orange', 'mango', 'apple', 'grapes', 'orange', 'mango'],
'price': ['40', '80', '30', '40', '30', '80'],
'quantity': ['200', '300', '300', '400', '200', '800']
})
# get the unique value of column fruits
print(df.fruits.unique())
df = df.groupby('domain')['ID'].nunique()
# import pandas library
import pandas as pd
# create pandas DataFrame
df = pd.DataFrame({'fruits': ['orange', 'mango', 'apple', 'grapes', 'orange', 'mango'],
'price': ['40', '80', '30', '40', '30', '80'],
'quantity': ['200', '300', '300', '400', '200', '800']
})
# get the count unique values of column fruits
print(df.fruits.value_counts())