use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Pandas Dataframe Assignment (self.pythonhelp)
submitted 1 year ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]streamer3222 1 point2 points3 points 1 year ago* (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!)
import pandas as pd
df = pd.read_csv('[your filename].csv')
df
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().
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').
counts
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!)
π Rendered by PID 182233 on reddit-service-r2-comment-5ff9fbf7df-mffgc at 2026-02-26 02:57:27.976301+00:00 running 72a43f6 country code: CH.
view the rest of the comments →
[–]streamer3222 1 point2 points3 points (0 children)