Nickel
Nickel

Reputation: 590

how to iterate over column and each iteration result save in result dataframe python

I have one dataframe with multiple columns ,i need to calculate same thing for all columns , is there any way to do this ? i have many columns so can not do one by one

df=pd.DataFrame({r'A':[1,24,69,67],r'A\0001\delta':[1,46,454,67],r'A\0002\delta':[1,46,454,67],r'A\00100\delta':[1,46,70,67]})

i want to calculate:
diff=df[r'A\0001\delta'].diff()
if diff greater than 60 save row in result dataframe 

same thing i want to do for more than 100 columns and want to save results in result dataframe by rows

Upvotes: 0

Views: 217

Answers (1)

Corralien
Corralien

Reputation: 120409

At least one value greater than 60 on a row

>>> df.loc[df.diff().gt(60).any(axis=1)]

    A  A\0001\delta  A\0002\delta  A\00100\delta
2  69           454           454             70

All values greater than 60 on a row:

>>> df.loc[df.diff().gt(60).all(axis=1)]

Empty DataFrame
Columns: [A, A\0001\delta, A\0002\delta, A\00100\delta]
Index: []

Upvotes: 1

Related Questions