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.
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.
WeeklyRating = billboard_2.apply(lambda x : x.count()-1, axis=1)
WeeklyRating
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'.
def bill_week(val):
for i, row in val.iterrows():
return(row.count()-1)
billboard_2.apply(bill_week)
I guess what I am asking is how do I convert that lambda function to a normal function.