首页 > 代码库 > pandas 运算
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))
pandas 运算
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。