I have a large dataframe (sample). I was filtering the data according to this code:
A = [f"A{i}" for i in range(50)]
B = [f"B{i}" for i in range(50)]
C = [f"C{i}" for i in range(50)]
for i in A:
cond_A = (df[i]>= -0.0423) & (df[i]<=3)
filt_df = df[cond_A]
for i in B:
cond_B = (filt_df[i]>= 15) & (filt_df[i]<=20)
filt_df2 = filt_df[cond_B]
for i in C:
cond_C = (filt_df2[i]>= 15) & (filt_df2[i]<=20)
filt_df3 = filt_df2[cond_B]
- When I print
filt_df3
, I am getting only an empty dataframe - why? - How can I improve the code, other approaches like some advanced techniques?
- I am not sure the code above works as outlined in the edit below?
- I would like to know how can I change the code, such that it works as outlined in the edit below?
Edit:
- I want to remove the rows based on columns (A0 - A49) based on
cond_A
. - Then filter the dataframe from 1 based on columns (B0 - B49) with
cond_B
. - Then filter the dataframe from 2 based on columns (C0 - C49) with
cond_C
.
Thank you very much in advance.