Python: get a frequency count based on two columns (variables) in pandas dataframe some row appers

emax :

Hello I have the following dataframe.

    Group           Size

    Short          Small
    Short          Small
    Moderate       Medium
    Moderate       Small
    Tall           Large

I want to count the frequency of how many time the same row appears in the dataframe.

    Group           Size      Time

    Short          Small        2
    Moderate       Medium       1 
    Moderate       Small        1
    Tall           Large        1
Andy Hayden :

You can use groupby's size:

In [11]: df.groupby(["Group", "Size"]).size()
Out[11]:
Group     Size
Moderate  Medium    1
          Small     1
Short     Small     2
Tall      Large     1
dtype: int64

In [12]: df.groupby(["Group", "Size"]).size().reset_index(name="Time")
Out[12]:
      Group    Size  Time
0  Moderate  Medium     1
1  Moderate   Small     1
2     Short   Small     2
3      Tall   Large     1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Frequency count based on two columns

R: append column in a dataframe with frequency count based on two columns

How do I get the sum of frequency count based on two columns?

Get row count using two columns with Pandas

Get joint-frequency of two binned variables from pandas dataframe?

Frequency count based on two columns in r

Adding a header/another row to a pandas dataframe based on some columns

Python pandas: Compare rows of dataframe based on some columns and drop row with lowest value

comparing columns with in dataframe and count frequency of match in python

Count the frequency of two linked columns in Python

How to get percentage count based on multiple columns in pandas dataframe?

Python, Pandas - count values based on multiple criteria in row and multiple columns

Equalize row count between columns in Python Pandas DataFrame

Python Pandas Dataframe: replace variable by the frequency count

Count of columns which as some value in pandas dataframe

Python Pandas: add missing row of two dataframe and keep the extra columns

frequency count of a column based on two other columns with datatable

(Python/Pandas) Divide two columns of pivoted dataframe based on a condition

Pandas Dataframe Generating Two new columns in a Dataframe that generate a count based on Conditional Parameters

Pandas dataframe grouping by two columns, count and sum

pandas dataframe column based on row and multiple columns

Get first row of dataframe in Python Pandas based on criteria

Setting the Frequency of a timeseries Pandas Dataframe with Two index Columns

get dataframe row count based on conditions

get dataframe row count based on conditions

sql how to get a count based on two columns

How to get the cumulative count based on two columns

How to fill a column in pandas dataframe based on some conditions set upon two different columns?

python - how to count the frequency of two strings in a row for a csv