Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Arne for Pandas new column using equation

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 latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>