How to subtract series and Data frame column wise in python?

ipython

#1

I have created a series and a Data frame in ipython notebook after creating them I have tried some arithmetic operation on them like subtraction.

frame = DataFrame(np.arange(12.).reshape((4, 3)), columns=list('bde'),
.....: index=['Utah', 'Ohio', 'Texas', 'Oregon'])
series = frame.ix[0]
frame - series
b d e
Utah 0 0 0
Ohio 3 3 3
Texas 6 6 6
Oregon 9 9 9

here the subtraction is row wise when I have tried doing subtraction column wise I am getting all missing value.

series3 = frame['d']
frame-series3


#2

@sid100158 - you are getting all missing value because you are a subtracting column of the frame with the index of series along the axis1(row-wise) and there is no value corresponding to that.Therefore, you are getting all NaN values.

If you want to perform the column-wise subtraction, you have to specify the axis.

frame.sub(series3, axis=0)
b d e
Utah -1 0 1
Ohio -1 0 1
Texas -1 0 1
Oregon -1 0 1 

Hope this helps!

Regards,
Hinduja