I am trying to figure out how I can apply cumulative functions to objects. For numbers there are several alternatives like cumsum and cumcount. The
well, you can define a custom function
def custom_cumsum(df):
from functools import reduce
nrows, ncols = df.shape
index, columns = df.index, df.columns
rets = {}
new_col = None
for col in df.columns:
try:
new_col = {col:df.loc[:, col].cumsum()}
except TypeError as e:
if 'set' in str(e):
new_col = {col:[ reduce(set.union, df.loc[:, col][:(i+1)]) for i in range(nrows)]}
rets.update(new_col)
frame = pd.DataFrame(rets, index=index, columns=columns)
return frame