We don't know what your window is for the moving average, so I selected 2, which will leave the first day's MA value as NaN
obviously.
The basic logic is groupby date, sum the cargo tons, and do the MA on that with a 2 day period. Use a left join to introduce that back to the original dataframe.
import pandas as pd
pd.merge(df,
df.groupby('DateOrigin')['CargoTons'].sum().rolling(2).mean().reset_index(name='Cargo MA'),
on='DateOrigin',
how='left')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…