How can i substract a single value from a column using pandas and python -


i have 1 data frame suppose:

name age hb ali  34  14 jex  16  13 aja  24  16 joy  23  12 

i have value "5" want substract each member of column "hb"

new column be:

hb 9 8 11 7 

what best method this...

thanks , regards.

simply subtract scalar value pandas.series , numerical columns pandas automatically broadcast scalar value , subtract each element in column. example -

df['hb'] - 5 #where `df` dataframe. 

demo -

in [43]: df out[43]:   name  age  hb 0  ali   34  14 1  jex   16  13 2  aja   24  16 3  joy   23  12  in [44]: df['hb'] - 5 out[44]: 0     9 1     8 2    11 3     7 name: hb, dtype: int64 

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 -

java - Android – MapFragment overlay button shadow, just like MyLocation button -