I'm wondering about the cleanest way to do what I'm facing. i'd like to create a new column for every value of a column in an existing dataframe. I don't know how many values can exist and for every line we would need to put all the values to 0 except if the option was toogled, which in this case would be 1. Ok that might not be easy to understand so I'll try to make an example with pseudo code too:
Let's imagine I have such a DataFrame:
| Name || Surname || Color || Genre |
| Paul || hellppp || Blue || Male |
| Erik || meeeeee || Red || Woman |
| Igor || plllsss || Green || Male |
Should become
| Name || Surname || Red || Blue | Green | Male | Woman
| Paul || hellppp || 0 || 1 | 0 | 1 | 0
| Erik || meeeeee || 1 || 0 | 0 | 0 | 1
| Igor || plllsss || 0 || 0 | 1 | 1 | 0
So basically for now I created an array containing all my qualitative values list so basically this:
qualitative_data = ['Color', 'Genre']
And now I'm willing to do something like:
for x in qualitative_data:
pass
df.set_index(['Name','Surname']).pivot_table(index=['Name','Surname'],columns=['Color','Genre'],aggfunc='nunique',fill_value=0).reset_index()vsdf.pivot_table(index=['Name','Surname'],columns=['Color','Genre'],aggfunc='nunique',fill_value=0).reset_index()....GroupBy.nuniquestill returns unique counts (guaranteed to be 1) for grouping columns, though it does not do so if a grouping column is part of the index.