The value_counts() function

The value_counts() function works only on series, and not DataFrames. It counts the number of times each variable occurs and provides a frequency table-like output:

pd.Series(["Pandas", "Pandas", "Numpy", "Pandas", "Numpy"]).value_counts()

The following is the output:

Frequency count for categorical series

The value_counts() function can also be applied to a numeric column. It results in a count of each time a value occurs:

sample_df["Nominations"].value_counts()

The following is the output:

The value_counts function used on the numeric column

It is more useful to count the occurrence of numeric values within the range of bins. The bins parameter of value_counts groups data into bins before counting:

sample_df["Nominations"].value_counts(bins = 2)

The following is the output:

The value_counts function with binning for the numeric columns
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset