0

我正在尝试将满足某些标准的 csv 文件中的surp值减去另一个满足另一个标准的surp值,我必须重复 60 次,如下所示:

[prime type == ' nl_unamb ' or 'nl_amb', target nr == '0', prime nr == '0'] - [prime type == ' en_unamb ' or 'en_amb', target nr = '0',素数 nr = '0'] =值 1

...

[prime type == ' nl_unamb ' or 'nl_amb', target nr == '59', prime nr == '59'] - [prime type == ' en_unamb ' or 'en_amb', target nr = '59',素数 nr = '59'] =值 60

为此,我尝试了以下代码:

import pandas as pd

df = pd.read_csv("surprisal.primed_extracted.csv")

for i in range(60):

    pr_nl = df.loc[(df['surp'])
                  & (df['prime_type'] == 'nl_unamb')
                  & (df['prime_type'] == 'nl_amb')
                  & (df['target_nr'] == i)
                  & (df['prime_nr'] == i)]

    pr_en = df.loc[(df['surp'])
                  & (df['prime_type'] == 'en_unamb')
                  & (df['prime_type'] == 'en_amb')
                  & (df['target_nr'] == i)
                  & (df['prime_nr'] == i)]
    
    df.['sub_prime_language'] = pr_nl.loc['surp'] - pr_en.loc['surp']

但是,我收到以下错误:

Traceback (most recent call last):
  File "calculate.py", line 13, in <module>
    & (df['prime_nr'] == i)]
  File "/usr/lib/python2.7/dist-packages/pandas/core/ops.py", line 786, in wrapper
    return filler(self._constructor(na_op(self.values, other.values),
  File "/usr/lib/python2.7/dist-packages/pandas/core/ops.py", line 758, in na_op
    result = lib.vec_binop(x, y, op)
  File "pandas/lib.pyx", line 914, in pandas.lib.vec_binop (pandas/lib.c:16248)
  File "pandas/lib.pyx", line 907, in pandas.lib.vec_binop (pandas/lib.c:16122)
TypeError: unsupported operand type(s) for &: 'float' and 'bool'

我期待听到任何人能提出的任何解决方案!

亲切的问候,
米津

4

0 回答 0