1
Guys I’m doing this looping here:
for i in range(1, len(candles)):
if candles['askclose'][i]> candles['askopen'][i]:
candles['Fechamento'][i]= 'alta'
But the jupyternotebook always returns me this Warning and sometimes hangs and does not advance, some idea of how to improve or make different this looping, to avoid Warning:
Warning:
C:\Users\Jair\Anaconda3\lib\site-packages\ipykernel_launcher.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
This is separate from the ipykernel package so we can avoid doing imports until
The mask as the friend suggested is great solution, but when I have a bigger loop like this:
for i in range(1, len(candles)):
tamanho_twin = 0
if candles['Fechamento'][i]=='baixa' and candles['Fechamento'][i-1] == 'alta':
if candles['askclose'][i] <= candles['askopen'][i-1] and candles['MA20'][i]<candles['MA20'][i-2]:
limite_sombraV= ((candles['askclose'][i]-candles['askopen'][i])*0.1)+candles['askclose'][i]
if candles['asklow'][i] == limite_sombraV:
tamanho_twin = candles['askclose'][i]+candles['askopen'][i]
candles['Twintower'][i] = 0
candles['Tamanho_Twin'][i] = candles['askclose'][i]+candles['askopen'][i]
I couldn’t just do:
candles['Fechamento'] = np.where(candles.askclose > candles.askopen, 'alta', '')
, nor will you need the bowfor
.– NoobSaibot
Here a similar question: Dataframe Pandas - Calculate column based on other
– NoobSaibot
Can you show "Candles"? Make a print (
print(candles)
) and show the result, or part of it.– Sidon
Sorry, now it’s another question.
– Sidon
@Noobsaibot, not why I also need to include the invesrso for 'low'
– Jair Miranda
@Jairmiranda just put the third parameter:
candles['Fechamento'] = np.where(candles.askclose > candles.askopen, 'alta', 'baixa')
, the first is the condition, second and third are the values that will be applied if the condition is true or false.– NoobSaibot
@Noobsaibot has a problem only I have the third situation, where Candles.askclose=Candles.askopen, there in this case do not know how to apply np.Where
– Jair Miranda
@Noobsaibot, these are 3 situations: Candles.askclose > Candles.askopen: high, Candles.askclose < Candles.askopen: 'low, Candles.askclose > Candles.askopen: 'neutral'
– Jair Miranda
@Jairmiranda does so:
candles['Fechamento'] = np.where(
 candles.askclose < candles.askopen,
 'baixa',
 np.where(candles.askclose == candles.askopen, 'neutro', 'alta'))
– NoobSaibot
@Noobsaibot, your solution was fantastic, I used for absolutely all loopings, thank you very much
– Jair Miranda