У меня есть вектор восприимчивых областей и вектор новых зараженных областей для каждого года в моей модели. Строки показывают разные возрастные группы населения, а столбцы представляют разные годы. Я пытаюсь «состарить» восприимчивые векторы с помощью np.roll. В случае эпидемии мне нужно вычесть вектор вновь зараженной области и «вызреть» остаток. В более ранних версиях это не было проблемой, однако по какой-то причине оно больше не работает и приводит к
__main__:172: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
Небольшая иллюстрация того, что я пытаюсь сделать, ниже
import numpy as np
import pandas as pd
years = range(10)
# Vector1 illustrates the susceptible individuals (n) indicates the different ages
vector1 = [100 for n in range(100)]
# Vector2 illustrates the newly infected individuals across ages. This constant should be subtracted for every year from the remainder at t-1.
vector2 = [10 for n in range(100)]
# In this df, I would like to store the remainder of susceptible individuals. Rows indicate the possible ages (n), columns the point in time (t).
df = pd.DataFrame([[0 for t in years] for n in range(100)])
for n in range(100):
for t in years:
# In the first year, no infection occurs and the column is just the vector of susceptible individuals
if t == 0:
df[n] = vector1
# In t+1 the epidemic starts and for every year I want to subtract the newly infected individuals (vector2) from the vector of susceptible (and not yet infected) individuals which I have calculated at t-1
elif t-1 >= 0:
df[t][n] = np.roll(np.subtract(df[t-1][n], vector2[n]), shift=1)