pandas 运算

Data frame 和 series 的运算:
横列相加减:按照index ,row 的方向直接相加减。frame-series
纵列相加减:按照 columns,运用算术函数,相加减。
frame.sub(series3, axis=0)



'''operation between data frame and series '''
import numpy as np
from pandas import Series, DataFrame

arr = np.arange(12.).reshape((3, 4))
print(arr)
print("arr[0]:")
print(arr[0])
print("arr-arr[0]:")
print(arr-arr[0])

print("Operation between data frame and series")
frame = DataFrame(np.arange(12.).reshape((4, 3)), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])

series = frame.ix[0]

print("frame is \n", frame)
print("series is \n", series)
print("frame-series: \n", frame-series)

series2 = Series(range(3), index=['b', 'e', 'f'])
print("if an index value is not found in either the DataFrame's columns or the Series' index")
print("series2:\n", series2)
print("frame+series2:\n", frame+series2)


series3 = frame['d']
print("frame is \n", frame)
print("series3 is \n", series3)
print("if you want to instead broadcast over the columns,matching on the rows,you have to use one columns: ")
print("frame.sub(series3,axis=0: \n", frame.sub(series3, axis=0))

转载于:https://www.cnblogs.com/wutongyuhou/p/6853207.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值