I have a df that can be seen below where I have the column 'sex' which indicates female/male and a column count which is the number of females/males present.
region | organismo_nombre | sexo | conteo |
---|---|---|---|
Región Metropolitana de Santiago | subsecretaria de derechos humanos | F | 56 |
Región Metropolitana de Santiago | subsecretaria de derechos humanos | M | 35 |
Región Metropolitana de Santiago | subsecretaria de evaluación social | F | 121 |
Región Metropolitana de Santiago | subsecretaria de evaluación social | M | 106 |
I want instead of having two rows, to have only one with column 'F' indicating the number of women and column 'M' indicating the number of men. I did some tests with df.pivot but I still had two rows left. How could I achieve the df below?
region | organismo_nombre | F | M |
---|---|---|---|
Región Metropolitana de Santiago | subsecretaria de derechos humanos | 56 | 35 |
Región Metropolitana de Santiago | subsecretaria de evaluación social | 121 | 106 |