xxxxxxxxxx
for col in df:
print(df[col].unique())
xxxxxxxxxx
# 10. Getting unique names of values in a column
df['Airline'].unique()
xxxxxxxxxx
import pandas as pd
# Assuming the dataframe is already loaded or created
df = pd.DataFrame({'column_name': [1, 2, 3, 3, 4, 4]})
# Finding the number of unique values in a column
unique_values = df['column_name'].nunique()
print("Number of unique values:", unique_values)
xxxxxxxxxx
# get the unique values (rows)
df.drop_duplicates()
xxxxxxxxxx
# 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())
xxxxxxxxxx
# 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 all columns
for col in df:
print(df
.unique())
xxxxxxxxxx
import pandas as pd
data = {
"Students": ["Ray", "John", "Mole", "Smith", "Jay", "Milli", "Tom", "Rick"],
"Subjects": ["Maths", "Economics", "Science", "Maths", "Statistics", "Statistics", "Statistics", "Computers"]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df["Subjects"].unique())
print(type(df["Subjects"].unique()))