How to substract a single value from column of pandas DataFrame

Simply subtract the scalar value from the pandas.Series , for numerical columns pandas would automatically broadcast the scalar value and subtract it from each element in the column. Example –

df['hb'] - 5 #Where `df` is your 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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)