使用Pandas中两列之间的差值创建新的数据帧

2024-09-26 22:13:01 发布

您现在位置:Python中文网/ 问答频道 /正文

这是数据帧的子集:

index  id   drug   sentences     SS1   SS2
1      2    lex     very bad      0     1
2      3    gym     very nice     1     1
3      7    effex   hard          1     0 
4      8    cymba   poor          1     1

我想找到SS1和SS2不同的行,然后基于它创建一个新的数据帧。输出应该是这样的:

^{pr2}$

这是我的代码:

df [['index','id', 'drug', 'sentences', 'SS1', 'SS2' ]] = np.where(df.SS1 != df.SS2)

但它有以下错误:ValueError: Must have equal len keys and value when setting with an ndarray

有什么建议吗?在


Tags: 数据iddfindexsentences子集verybad

热门问题