-1

How do I operate on a DataFrame with a Series for every column?

And for the reverse operation (Series - DataFrame)?

df = pd.DataFrame({0: [1,2,3], 1: [2,3,4]})
s0 = pd.Series([1,1,1])
   df              s0
   0  1          0  1
0  1  2          1  1
1  2  3          2  1
2  3  4          dtype: int64

I want s0-df.

   0  1
0  0 -1
1 -1 -2
2 -2 -3

My first inelegants solutions: -df.sub(s0, axis=0) ou (-df).add(s0, axis=0) !

An another idea?

dge
  • 41
  • 4
  • If you are presenting answers to the existing question, then post your suggestion there. Otherwise, you need to be clear about what differentiates your problem from the existing question. Otherwise, this is very difficult to follow – roganjosh Jul 28 '21 at 08:07

1 Answers1

0

A new idea :

df.rsub(s0, axis=0)

   0  1
0  0 -1
1 -1 -2
2 -2 -3
dge
  • 41
  • 4