Удалите строки, в которых все логические столбцы имеют значение False в Pandas DataFrame.Python

Программы на Python
Гость
Удалите строки, в которых все логические столбцы имеют значение False в Pandas DataFrame.

Сообщение Гость »


I have a df where I have different columns. I have a column for userId and other columns contain boolean values. I am trying to drop all rows where the value is False for all the boolean columns in that row. I tried using df.any() but it's not working. I also set the flag bool_only=True to only look at boolean column but it doesn't seem to work.

Using a sample dataframe:

data = [[5.5, True, False, True], [2.0, False, False, False], [1.5, True, True, False]] df = pd.DataFrame(data) print(df) print(df.any(axis=1, bool_only=True)) The result prints:

0 True 1 True 2 True But I want it to be:

0 True 1 False 2 True Since the second row has False False False value in the column 1, 2, and 3.

Does anyone know what I might be doing wrong?


Источник: https://stackoverflow.com/questions/780 ... -dataframe

Вернуться в «Python»