python - Count occurance of values within condition between column or rows -


i have data set goes this:-

2017-03-01  31.8  28.0     32.6 2017-04-01  31.6  28.0     32.6 2017-05-01  31.0  27.0     32.6 2017-06-01  31.0  27.0     32.4 2017-07-01  31.0  27.0     31.4 2017-08-01  30.0  27.0     32.6 

apart first column, rest of column temperature. compare values of 4th column (last right) other column values find if temperature values not more or less 2 deg (of 4th column). example, count how many times 3 columns (row wise) has value between 30.6 34.6.

is there function available under pandas that?

values of columns a b less more 2 of c

in [726]: (df[['a', 'b']].sub(df['c'], axis=0).abs() < 2).all(1).sum() out[726]: 0  in [727]: (df[['a', 'b']].sub(df['c'], axis=0).abs() < 2) out[727]:             b 0   true  false 1   true  false 2   true  false 3   true  false 4   true  false 5  false  false 

values between 30.6 34.6

in [671]: (df[['a', 'b', 'c']] > 30.6) & (df[['a', 'b', 'c']] < 34.6) out[671]:             b     c 0   true  false  true 1   true  false  true 2   true  false  true 3   true  false  true 4   true  false  true 5  false  false  true 

values between 30.6 34.6, columns in row true

in [672]: ((df[['a', 'b', 'c']] > 30.6) & (df[['a', 'b', 'c']] < 34.6)).all(1) out[672]: 0    false 1    false 2    false 3    false 4    false 5    false dtype: bool 

count of rows values between 30.6 34.6 columns

in [673]: ((df[['a', 'b', 'c']] > 30.6) & (df[['a', 'b', 'c']] < 34.6)).all(1).sum() out[673]: 0 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -