Home > Enterprise >  Pandas ".value_counts" while being used on a specific column in a datafile
Pandas ".value_counts" while being used on a specific column in a datafile

Time:10-10

I'm trying to count the number of listing id's in a file. The following code however, retrieves every single row and does not count the number of times the id is repeated.

numrows = 1000
df3 = pd.read_csv('calendar_dec18.csv', delimiter=',', nrows = numrows)
df3.dataframeName = 'calendar_dec18.csv'



count = df3['listing_id'].value_counts

print(count)

This is the output of the code

The output should look something like this:

listing_id | count

12351 | 51

777184 | 23

etc.

Could a kind soul help me out?

CodePudding user response:

Correct Usage:

df3['listing_id'].value_counts().reset_index()
  • Related