Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Examples

In [ ]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({'angles': [3, 4],
                   'degrees': [180, 360]},
                  index=['triangle', 'rhombus'])
df
Out[2]:
angles degrees
triangle 3 180
rhombus 4 360

Subtract a list and Series by axis with operator version:

In [7]:
df - [1, 2]
Out[7]:
angles degrees
triangle 2 178
rhombus 3 358
In [8]:
df.sub([1, 2], axis='columns')
Out[8]:
angles degrees
triangle 2 178
rhombus 3 358
In [9]:
df.sub(pd.Series([1, 1], index=['triangle', 'rhombus']),
       axis='index')
Out[9]:
angles degrees
triangle 2 179
rhombus 3 359