Hey guys, If I have a Car data set with 500 rows and columns, and Car Brands is a column, How do I know how many cars brands do I have in the dataset?
CodePudding user response:
First lets read the csv to a dataframe. For this, we need pandas library if you don't have it
open cmd and enter:
pip install pandas
Also, I saw certain repeating car brand names, so you need only unique car brand names.
import pandas as pd
df = pd.read_csv('path of your csv')
car_brands = df.brand.unique()
here, car brand is a list of all the unique car brand names. For number of car brand names:
print(len(car_brands))
CodePudding user response:
You can use nunique()
. If you want to specific columns unique (for example, car brand) count, you can just say dataframe['brand'].nunique()
.
This returns values and its counts.