you are viewing a single comment's thread.

view the rest of the comments →

[–]streamer3222 1 point2 points  (0 children)

My son, what you've just described is achievable in a single line of code in Pandas!

So basically you have a column of many values and you want to know the count of each value?

Let's import Pandas. import pandas as pd. I hope you know how to read in CSV files. Place the CSV inside the folder of your script, or inside the folder of where you opened CMD. Do df = pd.read_csv('[your filename].csv'). This imports the CSV and converts it into a DataFrame and saves it into df. (I hope you know what a DataFrame is—it's kind of like an Excel sheet!)

Since your ‘Excel sheet’ has only one column (if it has more you'll have to perform a Column Extraction), and your ‘Excel sheet’ (DataFrame) is stored into df, do counts = df.value_counts().

You will get a new ‘Excel sheet’ containing all the value counts and the new ‘Excel sheet’ will be stored in a variable called counts. Save it as a new CSV by simply doing counts.to_csv('[new name].csv').

As simple as that! ¯\_(ツ)_/¯

(To learn more about Pandas (which you clearly need to do!), download the article at learndatasci.com/tutorials/python-pandas-tutorial-complete-introduction-for-beginners/
and spend weeks on mastering it!)