I’m using apply to do value_counts() on two columns at once. I, however, want to set dropna=False.
This is not possible as I cannot supply any additional arguments for value_counts once I use it in apply.
I’ve seen lambda functions a couple of times but thought to leave it for now as I assumed it will be part of the Data Analyst with Python path I’m taking.
Does anybody know why I get the unexpected argument (dropna=False) error with DataFrame.value_counts()?
Because calling .apply(pd.value_counts(dropna=False)) immediately ran the value_counts function, versus passing the reference into the apply method. When you instead did .apply(pd.value_counts), then it passed in the function reference, and the apply method ran the function across each column. It’s the difference between a = sum and a=sum([1,2]).