Python 函数np.isreal在数据帧中做什么?
有人能解释一下下面的代码吗Python 函数np.isreal在数据帧中做什么?,python,pandas,Python,Pandas,有人能解释一下下面的代码吗 pima_df[~pima_df.applymap(np.isreal).all(1)] pima_df是一个数据帧。请查看文档或帮助(np.isreal) 确切地说,Numpy提供了一组方法,用于比较和执行数组元素操作: np.isreal : Determines whether each element of array is real. np.all : Determines whether all array element of a specifi
pima_df[~pima_df.applymap(np.isreal).all(1)]
pima_df
是一个数据帧。请查看文档或帮助(np.isreal)
确切地说,Numpy提供了一组方法,用于比较和执行数组元素操作:
np.isreal : Determines whether each element of array is real.
np.all : Determines whether all array element of a specific array evaluate to True.
tilde(~) : used for Boolean indexing which means not.
applymap: applymap works element-wise on a DataFrame.
all() : used to find rows where all the values are True.
~是invertdunder的运算符等价物,该dunder已被显式重写,用于对pd.DataFrame/pd.Series对象执行向量化逻辑求逆
布尔索引(~)的示例:
或
>>> df[~df.a.isin(df.b)] # same as above
a b c d
6 d b 3 3
7 d b 2 1
8 e c 4 3
9 e c 2 0
10 f c 0 6
11 f c 1 2
希望这会有所帮助。您正在提取至少出现一个复数的行 e、 g:pima_df=
a b
0 1 2
1 2 4+3j
2 3 5
结果将是:
a b
1 2 (4+3j)
简言之:
applymap
-在数据帧的每个元素上应用函数
np.isreal
-为真返回真,否则返回假
all
-如果轴上的每个元素都为true,则返回true,否则返回false
~
-对布尔索引求反有关详细信息,请查看此项:
a b
0 1 2
1 2 4+3j
2 3 5
a b
1 2 (4+3j)