При обработке некоторых данных медицинского обучения для подготовки классификатора к различным медицинским тестам я получил SettingWithCopyWarning от pandas. Я уже читал об этом и понял, что это происходит из-за последовательной индексации DataFrame, однако я не могу понять, в каком пункте моего кода ниже я использую цепную индексацию.
#Turn the 12 measurement result rows of each patient into one single row for each patient
#the different test results are named: result, result_1, ... , result_11 (for each result)
#the pid and age column is kept only once while all other column fields of the 12 measurement rows are concatenated
#into one single row, also the time field exists now 12 times per row
imputed_features.sort_values(by=['pid','Time'], inplace=True)
sorted_features = train_features.sort_values(by=['pid','Time'])
measurements = []
columns = []
for i in range(12):
measurements.append(imputed_features.groupby(['pid'], as_index=False).nth(i))
measurements[i].reset_index(drop=True, inplace=True)
if( i == 0 ):
columns = [i for i in measurements[i].columns]
else:
measurements[i].drop(['pid', 'Age'], axis=1, inplace=True)
for j in measurements[i].columns:
columns.append(f'{j}_{i}')
#the resulting aggregated_features DataFrame
aggregated_features = pd.concat(measurements[0:12], axis=1, ignore_index=True)
aggregated_features.columns = columns
aggregated_features.to_csv('aggregated_features.csv', index=False)