小编Sud*_*osh的帖子

在Python中有效地分割几何级数(Pythonic方式)

我正在尝试实现涉及几何级数(分割)的计算。有没有有效/高效的方法来做到这一点?该数据集有数百万行。我需要“Traded_quantity”列

标记 行动 交易数量
2019-11-05 09:25 0 0
09:35 2 3
09:45 0 0
09:55 1 4
10:05 0 0
10:15 3 56
10:24 6 8128

海龟 = 2(用户定义)

基本数量 = 1(用户定义)

    def turtle_split(row):
        if row['Action'] == 'BUY':
            return base_quantity * (turtle ** row['Marker'] - 1) // (turtle - 1)
        else:
            return 0
    df['Traded_quantity'] = df.apply(turtle_split, axis=1).round(0).astype(int)
Run Code Online (Sandbox Code Playgroud)

计算

对于第 0 行,Traded_quantity 应为零(因为标记为零)

对于第一行,Traded_quantity 应为 (1x1) + (1x2) = 3(标记 2 将分为 1 和 1,第一个 1 将与 …

python math data-science

7
推荐指数
1
解决办法
190
查看次数

标签 统计

data-science ×1

math ×1

python ×1