I have the following dataframe:
import pandas as pd
df = pd.DataFrame([
[1, 4],
[4, 6],
[8, 2],
[0, 8]
], columns=['a', 'b'])
How can I compute the difference between the first row vs the rest in a column like this:
df['operation_on_a'] = pd.DataFrame([
['1-1'],
['1-4'],
['1-8'],
['1-0']
])
df['operation_on_b'] = pd.DataFrame([
['4-4'],
['4-6'],
['4-2'],
['4-8']
])
and obtain result as follows using pandas only:
In numpy I found there is the triu_indices approach but I need to do this on the whole data table to obtain information from other columns.
Could you show me a way to solve this? Thank you!
