-1

At first, I combined a dataset with all the people which are living inside each state within each year, with a dataset of all the baby names and the count of them which were given each year. I want to create a column total_count of the names for each year next to the state so that I can look at how many people are named 'Josh' for example are in each state within each year and compare that to how many baby's are named 'Josh' in total each year.

columns = 'Count', 'Name','Sex', 'State', 'Year'

L. Koning
  • 1
  • 2
  • What exactly is your question? – GitPhilter Sep 24 '19 at 15:18
  • Please take a look at [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and provide a [mcve] including sample input, sample output, and code for what you've tried so far – G. Anderson Sep 24 '19 at 15:19
  • Please make a minimally reproducible problem statement with an example Dataset (say 10 rows of data and a few columns) and then also show given the proper transformations, how your final result is supposed to look like. It will help people suggest solutions quicker. – CypherX Sep 24 '19 at 15:21

1 Answers1

0

You could do something like:

df.[['Name','Sex','State','Year']].groupby(['Name','Sex','State','Year']).agg('count')

Where df is the name of your data frame. Though im not really sure what the actual question is because there's not enough info

DBA108642
  • 1,995
  • 1
  • 18
  • 55