0

我正在创建一个新的数据框: df_new = pd.DataFrame(columns = ['a', 'b', 'c','d','e','f'])

我已经有一个包含所有这些数据列的数据帧 df,这些数据列是使用 cTAKES 解析的,我用它来根据某些条件填充新的数据帧。

我还根据“c”列对 df 进行了排序: df.sort_values(by='c', inplace=True)

for i in range(len(df)):
    a=df.iloc[i]['a']
    b=df.iloc[i]['b']
    c=df.iloc[i]['c']
    d=df.iloc[i]['d']
    e=df.iloc[i]['e']
    f=df.iloc[i]['f']
    
    if i>=1:
        if pos_start>df_new.iloc[i-1]['c'] and pos_end>df_new.iloc[i-1]['d']:
            df_new=df_new.append({'a' : a, 'b' : b, 'c' : c,'d' :d , 'e': e, 'f':f}, ignore_index = True)
    elif i==0:
        df_new=df_new.append({'a' : a, 'b' : b, 'c' : c,'d' :d , 'e': e, 'f':f}, ignore_index = True)

当 i>=1 时出现以下错误:IndexError: single positional indexer is out-of-bounds

不知道我在这里缺少什么

4

0 回答 0