Clean And Analyze Employee Exit Surveys - Series.value_counts()

Screen Link:

My Code:

Replace this line with your code

What I expected to happen:

What actually happened: As following the project instruction all instruction work pretty good, but my question is how to implement the series.value_counts() method. I am facing a hard time acknowledging it without creating an index value. Applying it directly with the df name showing me an error. Can someone guide me on how can we apply the series.value_counts()

Replace this line with the output/error
[Basics (3).ipynb|attachment](upload://7PX7vWfmmPhJGaU5TPkzXd1g7Rk.ipynb) (828.7 KB)

hey @tusharsingh00

can’t see your notebook here. but if I understand your query correctly, this is what you need to do:
dataframe = df
column name = col1

df["col1"].value_counts() should give you the result.

if you use df["col1"].value_counts(normalize = True) then it will give you result in terms of proportion/ percentage.

hope it helps.

1 Like

When studying any library (in your case - pandas), be aware of what types of data structures you are applying methods to. value_counts is a series method. It is not defined from dataframe objects, so you must somehow transform dataframe to series before using it.
What you think you’re coding may not be what the code is doing, so print the type() of some intermediate code you wrote (such as breaking down a long method chain to inspect partial outputs).

If you want to do value_counts yourself, study df.groupby("one or more columns").size. This provides generally the same function as value_counts, but allows you to groupby more than 1 column, compared to value_counts which is analogously only grouping on 1 column.


Thank You! It helped me :slight_smile: I know this type of queries is silly but I don’t want to mess my learning by avoiding it.

Thank You! hanqi, Sometimes it gets really hard to recall what I learn from the past that why I just ask stubborn queries. But believe me data quest is the best platform, and all the moderators are always there to sort queries. :slight_smile: