《Python数据分析技术栈》第06章使用 Pandas 准备数据 11 pandas中的运算符 Operators in Pandas
Pandas uses the following operators that can be applied to a whole series. While Python would require a loop to iterate through every element in a list or dictionary, Pandas takes advantage of the feature of vectorization implemented in NumPy that enables these operators to be applied on every element in a sequence, eliminating the need for iteration and loops. The different types of operators are listed in Table 6-7.
Pandas 使用以下可应用于整个序列的运算符。Python 需要一个循环来遍历列表或字典中的每个元素,而 Pandas 则利用了 NumPy 中实现的矢量化功能,使这些运算符能够应用于序列中的每个元素,从而消除了遍历和循环的需要。表 6-7 列出了不同类型的运算符。
+addition), -(subtraction), *(multiplication),**(power),%(remainderoperator),/(division),//(floor division, for getting the quotient).
+(加法)、-(减法)、*(乘法)、**(幂)、%(余数运算符)、/(除法)、//(底除法,用于求商)。
the functions performed by arithmetic operators can be replicated using the following methods: add for +, sub for -, mul for *, div for /, mod for %, and pow for **.
可以使用以下方法复制算术运算符执行的功能:"+“用 add,”-“用 sub,”*“用 mul,”/“用 div,”%“用 mod,”**"用 pow。
== ( equality),<(less than),>(greater than),<=(less than or equalto),>=(greater than or equal to),!=(not equal to)
== ( 相等),<(小于),>(大于),<=(小于或等于),>=(大于或等于),!=(不等于)
&,|,~. pandas, like numpy, uses the bitwise operators (&,|,~) as logical operators, as these operators operate on every element of a series. note that these operators are different from the logical operators used in python, where the keywords and, or, and not are used.
与 numpy 一样,pandas 使用位运算符 (&,|,~) 作为逻辑运算符,因为这些运算符对数列中的每个元素都进行运算。请注意,这些运算符与 python 中使用的逻辑运算符不同,后者使用的关键字是 and、or 和 not。