I am trying to count the number of True/False values in a data frame like this:
df = pd.DataFrame({'a': [True, False, True],
'b': [True, True, True],
'c': [False, False, True]})
count_cols = ['a', 'b', 'c']
df['count'] = df[df[count_cols] == True].count(axis=1)
This is working fine on this example. But when I test it on my actual df (shape - (25168, 303)), I am getting the following error:
I Understood from - What does `ValueError: cannot reindex from a duplicate axis` mean? - that this usually occurs when there are duplicate values in the index and I have tried both df.reindex()
and df[~df.index.duplicated()]
, but I am still getting the same error message.