python - Selecting vlaues from a dataframe in pandas -


given dataframe of format

a b c d   .......  ........ 

i select rows value in column b greater 0.6*the last value in column.for eg,

input:

a b c  1 0 5  2 3 4  3 6 6  4 8 1  5 9 3 

output:

a b c  3 6 6  4 8 1  5 9 3 

i doing following,

x = df.loc[df.tail(1).index,'b'] 

which return series object corresponding index , value of coulmn b of last row of dataframe , then,

new_df = df.[df.b > x] 

but getting error,

valueerror: series lengths must match compare

how should perform query?

you need 1st take last value of column b using tail , multiply 0.6.

 df[df['b'] > df['b'].tail(1).values[0] * 0.6] 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -