I have the following dataframe:
df
id grp1 grp2
0 1 a NaN
1 2 b d
I need to create a new column with count of values from grp1 and grp2 columns.Something like below
df
id grp1 grp2 grp_count
0 1 a NaN 1
1 2 b d 2
One way of achieving this is using pandas apply with a function to get the count iterating row by row which will affect the performance.
Is there a way we can do it without using pandas apply?