gpt4 book ai didi

python - 索引错误 : Replacement index 1 out of range for positional args tuple

转载 作者:行者123 更新时间:2023-12-04 12:11:32 25 4
gpt4 key购买 nike

我正在学习教程,但不知道为什么会出现此错误:

    <ipython-input-61-d59f7a5a07ab> in extract_featuresets(ticker)
2 tickers, df = process_data_for_labels(ticker)
3 df['{}_target'.format(ticker)] = list(map(buy_sell_hold,
----> 4 df['{}_{}1d'.format(ticker)],
5 df['{}_{}2d'.format(ticker)],
6 df['{}_{}3d'.format(ticker)],

IndexError: Replacement index 1 out of range for positional args tuple
这是我的代码:
tickers, df = process_data_for_labels(ticker)
df['{}_target'.format(ticker)] = list(map(buy_sell_hold,
df['{}_{}1d'.format(ticker)],
df['{}_{}2d'.format(ticker)],
df['{}_{}3d'.format(ticker)],
df['{}_{}4d'.format(ticker)],
df['{}_{}5d'.format(ticker)],
df['{}_{}6d'.format(ticker)],
df['{}_{}7d'.format(ticker)],))
这是教程的链接: https://www.youtube.com/watch?v=zPp80YM2v7k

最佳答案

您的格式字符串在 format 中需要两个参数而你只路过一个 ticker作为论据。
ticker是一个二元素列表或元组,你可以这样做:

df['{}_{}1d'.format(*ticker)]
否则删除一个大括号:
df['{}_1d'.format(ticker)]

关于python - 索引错误 : Replacement index 1 out of range for positional args tuple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63655115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com