我在尝试使用pandas实现以下功能:
df['X'] = df['C'].where(row is <= current row).sum()
df['Y'] = df['C'].where(row is >= current row).sum()
什么是正确的 Pandas 语法,使其对列 C 中高于或等于当前行的数据进行求和?
我在尝试使用pandas实现以下功能:
df['X'] = df['C'].where(row is <= current row).sum()
df['Y'] = df['C'].where(row is >= current row).sum()
df['X'] = df['C'].cumsum()
df['Y'] = df['C'].sum() + df['C'] - df['X']
# or
# df['Y'] = df.iloc[::-1].cumsum()
让我们尝试使用expanding
,您可以选择所需的聚合函数等,如mean
/std
df['X'] = df['C'].expanding().sum()
df['Y'] = df['C'].iloc[::-1].expanding().sum()
cumsum
做到这一点? - Brannondf['C'].shift().cumsum()
。 - Quang Hoang