【发布时间】:2017-07-29 16:17:26
【问题描述】:
假设我有一个包含 3 列的数据框,全部为浮点类型,将其命名为 DT1。 现在,如果我想通过查询 DT1 从 DT1 创建另一个数据帧,假设第二个数据帧称为 DT2。
DT2 = DT1.query(‘(column1/column2) == (column3/column2)’)
这只有在等式的两侧完全匹配时才有效。 如果我只想比较两侧的整数结果怎么办?
喜欢:
DT2 = DT1.query(‘(column1/column2).astype(int) == (column3/column2)’).astype(int)
上面的例子不行,有什么解决办法吗?
PS:
DT2 = DT1.loc(‘(DT1[column1]/DT1[column2]).astype(int) == (DT1[column3[/DT1[column2]).astype(int)’)
会起作用。我很好奇它是否可以通过查询工作。
谢谢!
【问题讨论】:
标签: python pandas dataframe types casting