def _valid_price(g):
return (((g.max() - g.min()) / g.min()) < 0.223).all()
# 按照日期分组
days = raw.groupby(level=0).agg(
{'opening_price': lambda g: _valid_price(g) and g[0] or 0,
'ceiling_price': lambda g: _valid_price(g) and np.max(g) or 0,
'floor_price': lambda g: _valid_price(g) and np.min(g) or 0,
'closing_price': lambda g: _valid_price(g) and g[-1] or 0,
'volume': 'sum',
'amount': 'sum'})
days.head()
能不能帮忙解读一下
Conclusion: When the grouping objects (indexes) are repeated [that is, the dates may be repeated], then
level = 0
the indexes are the same and separatedWhen
level
is greater than or equal to 1. The dimension of the object is greater than or equal to 3 (dimensions)Example:
It is recommended to take a look at the documentation: http://pandas.pydata.org/pand...