任何我可以帮助我说出 Pandas 中这两个语句之间的区别-python
df.where(df['colname'] == value)
和
df[(df['colname'] == value)]
为什么我在输出数据帧中得到不同的大小
最佳答案
根据 where
的文档:
Return an object of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other.
所以
where
的目的与使用括号过滤略有不同,因为它会为您提供与您运行它的数据框形状相同的结果。目标在文档的注释中:
The where method is an application of the if-then idiom. For each element in the calling DataFrame, if
cond
isTrue
the element is used; otherwise the corresponding element from the DataFrameother
is used
关于python-3.x - df.where( ) 和 df [ (df [ ] == ) ] 在 Pandas 中的区别,python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40332974/