python-3.x - df.where( ) 和 df [ (df [ ] == ) ] 在 Pandas 中的区别,python

标签 python-3.x pandas

任何我可以帮助我说出 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 is True the element is used; otherwise the corresponding element from the DataFrame other is used

关于python-3.x - df.where( ) 和 df [ (df [ ] == ) ] 在 Pandas 中的区别,python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40332974/

相关文章:

python - 获取列表中所有可能的有序子列表

python - 意外异常 : name 'basestring' is not defined when invoking ansible2

python - 如何自动化传递给pandas.read_sql的参数?

python - 拆分 pandas 数据框中字符串中的第 n 个元素

python - 使用 issubset 比较两个 pandas 数据框列之间的设置值

python - csv.writer 打印带有前缀和引号的 "bytes"

python - Flask-Limiter 不适用于基于 Flask-Restful API 的应用程序

python-3.x - 根据条件去除重复

python - 基于条件的索引范围

python - 将字典迭代转换为 pandas 数据框