I have a csv file containing many products (40k) and many columns with price,category,name... I want to count how many rows (products) are there in each category (taking them directly from the file) and display it. How can i do this using pandas? Or is it better to use something else?
Count rows with same values in specific column using pandas
Pandas can probably be used for this. have you tried anything yet? Your question is quite general, perhaps you can add some of what you've tried so far. –
Nostomania
I've tried the answer to this question and it works –
Portative
import pandas as pd
df = pd.read_csv(PATH_TO_CSV, usecols=['category','products'])
print(df.groupby(['category']).count())
The first line creates a dataframe with two columns(categories and products) and the second line prints out the number of products in each category.
Thank you very much –
Portative
© 2022 - 2024 — McMap. All rights reserved.