title: Iterate through rows in Dataframe using a function and count the non NA values
body: <p>My Dataframe: billboard_2
  <a href="https://i.stack.imgur.com/ZHQco.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZHQco.png" alt="enter image description here" /></a></p>
  <p>I need to count the number of weeks a song is on billboards by using an apply function and a simple python function. But apparently, I am not able to do so.</p>
  <p>I managed to do it via the lambda function but I am supposed to use apply function. The output I am getting lambda function is exactly what I need using the normal function.</p>
  <pre><code>WeeklyRating = billboard_2.apply(lambda x : x.count()-1, axis=1)
  
  WeeklyRating
  </code></pre>
  <p>Output using lambda function
  <a href="https://i.stack.imgur.com/FbKSP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FbKSP.png" alt="enter image description here" /></a></p>
  <p>I tried converting that lambda function to a normal function but each time I am getting some error.
  Following is what I tried and I got an error saying - 'Series' object has no attribute 'iterrows'.</p>
  <pre><code>def bill_week(val):
      for i, row in val.iterrows():
          return(row.count()-1)
  
  billboard_2.apply(bill_week)
  </code></pre>
  <p>I guess what I am asking is how do I convert that lambda function to a normal function.</p>