title: Using pandas groupby and numpy where together in Python
body: <p>I am a newbie to python!</p>
  
  <p>I need to use pd.groupby() function under np.where().</p>
  
  <p>Below is the screen capture of my data set:</p>
  
  <p><a href="https://i.stack.imgur.com/vb0Ju.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vb0Ju.png" alt="enter image description here"></a></p>
  
  <p>Following is my code: </p>
  
  <pre><code>df = pd.read_csv("/Users/gautam/Desktop/data.csv")
  df.head()
  
  grouped = df.groupby('Occupation')['Emp_Code'].count() #Calculating Count of Employees by Occupation
  
  np.where(df['Gender']=='M', df.groupby('Occupation')['Emp_Code'].count()/grouped*100,0)
  </code></pre>
  
  <p>Basically I need to calculate the male ratio per occupation. </p>
  
  <p>Any help would be highly appreciated.</p>