Arun Arun - 11 months ago 188
Python Question

filter rows in pandas dataframe with specified interval

I have a dataframe table with shape (104238, 88). I want to extract only rows with values either 1 or 0 (not boolean)

Dataframe_input

Index C1 C2 C3 C4.... C88
R1 200 0 20 40 1068
R2 0 0 0 0 1
R3 1 1 1 1 0


After subsetting, I want R2, R3 to be extracted. i.e all elements in entire row is either 0 or 1

I tried,

import pandas as pd
df = pd.read_csv('Dataframe.txt', sep='\t', index_col='Index')
df2 = df[[df.columns].all(axis=1) <2]


I get the error,


AttributeError: 'list' object has no attribute 'all'


What is the error here? Please help.

Thanks in advance,

AP

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download