how can I divide two separate counts in pandas?

17 Views Asked by At

Below are the two separate counts that I have. I need to divide the first count"team1" by the second count "new". I am trying to get the percentage of each type in "new".

team1 = plays.groupby('posteam')['posteam'].count()
plays.groupby('posteam')['posteam'].count()
posteam
ARI    1516
ATL    1331
BAL    1515
BUF    1596
CAR    1422
CHI    1382
CIN    1690
CLE    1363
DAL    1603
DEN    1335
DET    1390
GB     1448
HOU    1356
IND    1380
JAX    1361
KC     1709
LA     1700
LAC    1456
LV     1526
MIA    1432
MIN    1434
NE     1446
NO     1378
NYG    1370
NYJ    1356
PHI    1463
PIT    1545
SEA    1267
SF     1570
TB     1636
TEN    1529
WAS    1393
Name: posteam, dtype: int64
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
​
play_type
#number of times each team had each unique playtype
new = plays.groupby(['posteam','play_type']).size()
display(new)
posteam  play_type  
ARI      extra_point     49
         field_goal      38
         kickoff         86
         no_play         89
         pass           669
         punt            57
         qb_kneel        17
         run            497

I've tried transform and sum etc but keep getting variors errors.

0

There are 0 best solutions below