编写一个函数,该函数应满足行基础上的条件并返回预期结果
def bt_quantity(df):
df = bt_level(df)
df['Marker_change'] = df['Marker'] - df['Marker'].shift(1).fillna(0).round(0).astype(int)
df['Action'] = np.where(df['Marker_change'] > 0, "BUY", "")
def turtle_split(row):
if df['Action'] == 'Buy':
return baseQ * (turtle ** row['Marker'] - 1) // (turtle - 1)
else:
return 0
df['Traded_q'] = df.apply(turtle_split, axis=1).round(0).astype(int)
df['Net_q'] = df['Traded_q'].cumsum().round(0).astype(int)
print(df.head(39))
return df
Run Code Online (Sandbox Code Playgroud)
这是一个常见问题,我没有在代码中使用任何“和”或“或”。仍然收到以下错误
我尝试将 str 更改为 int(BUY >> 1),但没有进展。PS 数据集很大,我正在使用多个模块和函数来处理这个项目。
python ×1