Unstack and return value counts for each variable?
You can set Gender
as index and sum:
s = df.set_index('Gender').iloc[:, 1:]
s.eq(s.columns).astype(int).sum(level=0)
Output:
Python Bash R JavaScript C++
Gender
Male 1 0 0 1 0
Female 0 0 1 1 1
Prefer not to say 1 1 0 0 0
Another idea would be to apply
join
values along axis 1, get_dummies
then groupby
:
(df.loc[:, 'Python':]
.apply(lambda x: '|'.join(x.dropna()), axis=1)
.str.get_dummies('|')
.groupby(df['Gender']).sum())
[out]
Bash C++ JavaScript Python R
Gender
Female 0 1 1 0 1
Male 0 0 1 1 0
Prefer not to say 1 0 0 1 0