python - How to filter rows with pandas without using the column name - loop filter -
i trying filter rows in dataframe using pandas instead of using:
df[(df.columna == 1)]
i want able this:
i = 'a' x = 'column'+'i' df[(df.x == 1)]
my aim loop in columns filters. improve if this:
i = x = 'column'+'i' y = 1 df[(df.x == y)]
allowing me loop in columns , loop in filter types:
thanks!
if trying grab series dataframe, having problem because .
notation won't allow variable, utilize brackets instead:
i = 'a' column = 'column' + df = df[df[column] == 1]
you create mask in loop , apply @ once:
column_base = 'column' suffixes = ['a','b','c','d'] mask = none in suffixes: column = column_base + if mask none: mask = df[column] == 1 else: mask &= df[column] == 1 df = df[mask]
python pandas dataframes
No comments:
Post a Comment