###前提・実現したいこと
python初心者です。
close>20ma列がSからL,LからSに変わった場合にclose列の値を返して、そうでない場合はposition列の直前の文字を返す、という条件で、一行ごとに条件通りの処理をさせたいのですが、ValueErrorとなりうまくいきません。
for文の書き方がおかしいのだろうということしかわかりません。どこが間違っているかご教示お願いします。
date open high low close 20ma change close>20ma
2011-01-26 1390 1445 1388 1432 NaN 2.652330 S
2011-01-27 1410 1448 1410 1430 NaN -0.139665 S
2011-01-28 1401 1410 1390 1393 NaN -2.587413 S
2011-01-31 1387 1400 1387 1392 NaN -0.071788 S
2011-02-01 1392 1397 1369 1370 1352.85 -1.580460 L
2011-02-02 1385 1385 1335 1355 1352.60 -1.094891 L
2011-02-03 1345 1345 1311 1326 1348.95 -2.140221 S
2011-02-04 1326 1330 1326 1330 1345.50 0.301659 S
エラーメッセージ
ValueError: Length of values does not match length of index ###該当のソースコード
df['position'] = []
for i in range(len(df)):
np.where(df.iloc[i, 6] != df.iloc[i+1, 6], df.iloc[i+1, 3], df.iloc[i, 7])
df['position'].append(i)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。