How can we do counts of items in a data frame and asign results to a new column in the dataframe?

I have street addresses that look like this.

250 EAST HOUSTON STREET
211 EAST 3RD STREET
182 EAST 2ND STREET
511 EAST 11TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
324 EAST 4TH STREET
754 EAST 6TH STREET

How can I get counts, in the same data frame, like this?

250 EAST HOUSTON STREET 3
211 EAST 3RD STREET     1
182 EAST 2ND STREET     1
511 EAST 11TH STREET    1
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
324 EAST 4TH STREET     8
754 EAST 6TH STREET     1

The name of the field that I want to count is 'Street'. I found some code that counts dupes, but it does a group by and takes everything into a new data frame. I want to assign counts to a new column in the same data frame. Thanks!



Read more here: https://stackoverflow.com/questions/64397793/how-can-we-do-counts-of-items-in-a-data-frame-and-asign-results-to-a-new-column

Content Attribution

This content was originally published by Ash at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: