将序列放到给定数组的底面

问题描述 投票:1回答:1

如何有效地将pandas系列(或索引级别)平铺到给定的数组(系列,索引),即将Series中的每个元素x映射到楼板数组中的最大元素y,使得[ C0]?

这里是一个例子:

y <= x

您可以假设序列和数组都按升序排序。

python arrays pandas series floor
1个回答
2
投票

尝试import pandas as pd # the series x = pd.Series([1.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1, 11.11]) # the floor array y = pd.Series([1.0, 4.0, 10.0]) # expected result (can be a numpy array, a Series, a list, etc...) z = [1.0, 1.0, 1.0, 1.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 10.0, 10.0]

pd.cut

输出:

pd.cut
© www.soinside.com 2019 - 2024. All rights reserved.