表1
x y z amount absolute amount
121 abc def 500 700
131 fgh xyz -800 800
121 abc xyz 900 900
131 fgh ijk 800 800
141 obc pqr 500 500
151 mbr pqr -500 500
141 obc pqr -500 500
151 mbr pqr 900 900
应用以下代码,我得到所需的输出-
c=df.groupby(['x','y'])['amount'].transform('sum')
df[c.ne(0) & c.abs().ne(df.absolute_amount)]
表2
x y z amount absolute amount
121 abc def 500 700
121 abc xyz 900 900
151 mbr pqr -500 500
151 mbr pqr 900 900
但是当我进一步想要一个表,其中返回表1中不在表2中的行,并生成一个新表(表3)
并对表3-
lis = anti_join_all_cols(TABLE_1, TABLE_2)
dd = lis.groupby(['x','y'])['amount'].transform('sum')
TABLE_3 = lis[c.ne(0) & c.abs().ne(df.Absolute Amount)]
将弹出以下警告-
UserWarning: Boolean Series key will be reindexed to match DataFrame index.
“c”是数据帧df&;上的操作生成的序列;它的索引与表3的数据帧'lis'不同,您试图将这两个索引放在一起,因此出现错误。如果最后一个lise是
Table_3=lis[dd.ne(0) & dd.abs().ne(lis.absolute_amount)]
,您将不会得到这个错误(但是,您将得到一个空的数据帧)相关问题 更多 >
编程相关推荐