【发布时间】:2021-05-02 22:20:36
【问题描述】:
下面的函数使用切片来一次获取 2 个索引之间的最大值。所以它在0 and 10 和10 and 12 之间得到最大值。该函数源自对这篇帖子post 的回答。有没有办法可以像pd.Series() 这样的熊猫函数形式替换列表理解。或者如果可能的话,将其作为一个 numpy 函数。
list_ = np.array([9887.89, 9902.99, 9902.99, 9910.23, 9920.79, 9911.34, 9920.01, 9927.51, 9932.3, 9932.33, 9928.87, 9929.22, 9929.22, 9935.24, 9935.24, 9935.26, 9935.26, 9935.68, 9935.68, 9940.5])
indexes = np.array([0,10,12,14])
chunks = np.split(list_, indexes[1:-1])
MAX=([c.max() for c in chunks])
【问题讨论】:
-
为什么要这样做?是出于性能原因还是需要 numpy 数组形式的结果?
-
df.iloc[0:10].max()只需将 0/10 替换为您想要的
标签: python pandas list numpy slice