I need to drop all the rows which has all FALSE from col2 to col6 using python. I think "df = df[df.any(axis=1)]" will also take columns "id" and "col1" into consideration. I need to exclude columns "id" and "col1".
Appreciate your help.
I tried to iterate through the loop for the data extracted from csv as below
import pandas as pd
columns_to_keep = ['col1']
for col in df.columns[1:]:
if df[col].any():
columns_to_keep.append(col)
filtered_df = df[columns_to_keep]
But I am getting error list indices must be integers or slices, not str