Frequency count of values in a column of a pandas DataFrame

Andreas

Please help me find a solution for this: I have a Pandas DataFrame containing website visitors and date of their visit. Now I want to know, how many people visit once, twice, etc.

I start with a table:

Visitor |   Date
---------------------
   A    |    Jan-1st
   B    |    Jan-1st
   C    |    Jan-2nd
   D    |    Jan-2nd
   A    |    Jan-2nd

I want to end up with a result in the form of:

Frequency |  No. of
of visits |  visitors
-----------------------
   1      |      3
   2      |      1
Zero

Usevalue_count on Visitor column twice.

In [182]: df.Visitor.value_counts().value_counts()
Out[182]:
1    3
2    1

Details

First get, visitor-wise visits, then you get group the similar counts.

In [183]: df.Visitor.value_counts()
Out[183]:
A    2
D    1
B    1
C    1
Name: Visitor, dtype: int64

In [188]: (df.Visitor.value_counts()
             .value_counts()
             .reset_index()
             .rename(columns={'index': 'Freq of visits', 'Visitor': 'No. of visitors'}))
Out[188]:
   Freq of visits  No. of visitors
0               1                3
1               2                1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Count frequency of values in pandas DataFrame column

Count frequency of values in pandas DataFrame

Count the frequency that a bunch of values occurs in a dataframe column

Frequency count based on column values in Pandas

Sort Pandas DataFrame by frequency of values in one column

Count freq of one column values in pandas dataframe and tag each row with its frequency occurence number

How can I get a frequency count of values delimited by comma in a pandas dataframe column?

pandas count frequency of column value in another dataframe column

Count frequency of value in pandas column where values in another column are similar

How can I count the frequency of repeated values in dataframe column?

How to create a dataframe column from values with frequency count?

Count the frequency of characters at a position in a string in a Pandas DataFrame column

Count pattern frequency in pandas dataframe column that has multiple patterns

How to count frequency of select values in Python pandas dataframe

Count frequency of values in a column in PIG?

sort and count values in a column DataFrame (Python Pandas)

Sort by Frequency of Values in a Column - Pandas

grouping words inside pandas dataframe column by another column to get the frequency/count

Count frequency of value in column in dataframe in Spark

count the frequency that a value occurs in a dataframe column

count the frequency that a value occurs in the end of a dataframe column

Python Pandas Dataframe: replace variable by the frequency count

Frequency count across whole pandas dataframe

Count frequency of number appearance in full pandas dataframe

How to plot frequency count of pandas column?

How to count the frequency of variable in pandas column

Pandas: count frequency of values and convert into columns

count frequency of values by week using pandas then plot

How to estimate count for Pandas dataframe column values based on multiple conditions?