Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexError: Replacement index 1 out of range for positional args tuple

I am following a tutorial and I don't know why I got this error:

    <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

Here is my code:

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)],))

Here is the link to the tutorial: https://www.youtube.com/watch?v=zPp80YM2v7k

like image 234
balexander1 Avatar asked Aug 30 '20 07:08

balexander1


2 Answers

Your format string need two arguments in format while you are only passing in one ticker as argument.

If ticker is a two element list or tuple, you can do this:

df['{}_{}1d'.format(*ticker)]

Otherwise remove one curly brackets:

df['{}_1d'.format(ticker)]
like image 99
fusion Avatar answered Oct 21 '22 19:10

fusion


If you want same value in { } of

df['{ }_{ }1d'.format(*ticker)]

Try like it this:

df['{0}_{0}1d'.format(*ticker)]

I solved my problem similar your problem.

like image 35
LeeYongBlood Avatar answered Oct 21 '22 19:10

LeeYongBlood