I have a Pandas DF with a column "label". Let's say there are five rows in the DF and the values of labels are as follows [1, 1, 1, 0, 0]. Is there a built-in function in Pandas so I can remove one row with label 1 so the values are evenly distributed (count of 0's and 1's is the same)?
Asked
Active
Viewed 26 times
0
-
What do you mean by evenly distributed? That they have the same amount of 1 and zeros? – Dani Mesejo Jul 23 '22 at 09:32
-
I edited the original so it should be more clear. – hauki_123 Jul 23 '22 at 09:38
-
So if you 10 1s and 2 0s you want a Dataframe with 2 1s and 2 0s? – Dani Mesejo Jul 23 '22 at 09:39
-
Does this answers your question: https://stackoverflow.com/questions/45839316/pandas-balancing-data – Dani Mesejo Jul 23 '22 at 09:43
-
That would have equal count of 1s and 0s, so no rows would need to be removed. If there was 16 1s and 10 0s, I would like to remove 6x 1s. Thanks for clarifying this! – hauki_123 Jul 23 '22 at 09:43
-
I believe it does, thanks for the help. – hauki_123 Jul 23 '22 at 10:06