Quantcast
Channel: Pandas new column using equation - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Arne for Pandas new column using equation

$
0
0

If you first propagate the slope to all subsequent missing values, you can easily calculate the 'fit' values step by step, just adding the slope to the previous value cumulatively:

df['slope'] = df.slope.fillna(method='ffill')fit = df.avg.values.copy()missing = df.avg.isna()for i in range(len(df)):    if missing[i]:        fit[i] = fit[i - 1] + df.slope[i]df['fit'] = fit

Viewing all articles
Browse latest Browse all 2

Trending Articles