i have a dataframe with 50 columns and 7777 rows. the first 4 columns are object type and all the remaining are int type. i would to like to filter the dataframe if all the columns from column 3 to column 50 are zero. kindly help me filter using python
tried:
df.apply(lambda row: row[df.iloc[:,3:].isin(['0'])])
error:
TypeError: Indexing a Series with DataFrame is not supported, use the appropriate DataFrame column
Your filter condition is - rows where all of the values for columns 3+ equal 0. Use DataFrame.loc with the boolean result.
df.loc[(df.iloc[:,3:]=='0').all(axis=1)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.