pandas 运算
Posted 小麦粒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 运算的主要内容,如果未能解决你的问题,请参考以下文章