Python Forum

Full Version: looping in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
df1 df2 df3 df4
e5,e100,c .... ku,kl,kd,c ... o1,c ... o20,c


e5>e100 and c<ku and o1>o10
s=1
e5<e100 and c>kd and o1<o10
s=-1
if both condition not satisfied
s=0


can some one tell me how to loop data from different dataframe '
or i need to make a single dataframe also how can i make single dataframe df
i used concat merge and join but my data is getting nan
Hi, jazzy.

What you've got right now?
Please use the tags (python code, output, error) to post more info about your issues.
for i, r in enumerate (aapl.iterrows()):
if r[1]['a'] < r[1]['b'] and r[1]['c'] > r[1]['k1'] and r[1]['o1'] > r[1]['o1'] :
short_long_signal = 1
elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1][k2'] and r[1]['o2'] < r[1]['o2'] :
short_long_signal = -1

else:
short_long_signal = 0
print (short_long_signal)

I had following output
0
0
1
0
0
-1
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
how can I have the data frame of out put and plot it
Hi,
You have little Sheet in Your Code, but maybe this will be useful for You:
a=[]
for i, r in enumerate (aapl.iterrows()):
    if r[1]['a'] < r[1]['b'] and r[1]['c'] > r[1]['k1'] and r[1]['o1'] > r[1]['o1']:
        a.append(1)
    elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1][k2'] and r[1]['o2'] < r[1]['o2']:
        a.append(-1)
    else:
        a.append(0)
and use matplotlib to make a nice graphical interpretation... :)
can u tell me how to make graphical interpretation using matplotlib

a=[]
for i, r in enumerate (aapl.iterrows()):
if r[1]['a'] < r[1]['b'] and r[1]['c'] > r[1]['k1'] and r[1]['o1'] > r[1]['o1']:
a.append(1) buy stock
elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1][k2'] and r[1]['o2'] < r[1]['o2']:
a.append(-1) sell stock
else:
a.append(0) do nothing

#how can i write code for
if stock already brought
sell it wen
a>b
if stock already sold
buy it wen
a<b
wat conditions to be included in this
to satify the conditions
(Jul-16-2018, 05:51 AM)jazzy Wrote: [ -> ]for i, r in enumerate (aapl.iterrows()):
if r[1]['a'] < r[1]['b'] and r[1]['c'] > r[1]['k1'] and r[1]['o1'] > r[1]['o1'] :
short_long_signal = 1
elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1][k2'] and r[1]['o2'] < r[1]['o2'] :
short_long_signal = -1

else:
short_long_signal = 0
print (short_long_signal)

I had following output
0
0
1
0
0
-1
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
how can I have the data frame of out put and plot it
is this correct
a=[]
for i, r in enumerate (aapl.iterrows()):
if r[1]['a'] < r[1]['b'] and r[1]['c'] > r[1]['k1'] and r[1]['o1'] > r[1]['o1']:
a.append(1) buy stock
while a.append(1) and r[1]['a'] > r[1]['b']:
a.append(-1)# sell if brought

elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1][k2'] and r[1]['o2'] < r[1]['o2']:
a.append(-1) sell stock
while a.append(-1) and r[1]['a'] < r[1]['b']:
a.append(1)# buy if sold
else:
a.append(0) do nothing
You need to use python tags when posting code. We can't see the indentation to properly evaluate your code otherwise. See the BBCode link in my signature below for instructions.
ok I will use the proper quote and repost it

 short_long_signal=[]
for i, r in enumerate (aapl.iterrows()):
    if r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1]['k1'] and r[1]['o1'] > r[1]['o2']  :
        short_long_signal.append(1) #buy
        while  short_long_signal.append(1) and r[1]['a'] > r[1]['b']:
               short_long_signal.append(-1)# sell if brought
        
    elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1]['k1'] and r[1]['o1'] < r[1]['o2'] :
        short_long_signal.append(-1)#sell
        while  short_long_signal.append(-1) and  r[1]['a'] < r[1]['b']:
                 short_long_signal.append(1)#buy if sold
        
    else:
        short_long_signal.append(0)#do nothing
I want to make a buy signal closing the previous sell signal and a sell signal closing previous buy signal can some one tell me the code below is correct or not because m nt getting signal generated
short_long_signal=[]
for i, r in enumerate (aapl.iterrows()):
    if r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1]['k1'] and r[1]['o1'] > r[1]['o2']  :
        short_long_signal.append(1) #buy
        while  short_long_signal.append(1) and r[1]['a'] > r[1]['b']:
               short_long_signal.append(-1)# sell if brought
         
    elif r[1]['a'] > r[1]['b'] and r[1]['c'] < r[1]['k1'] and r[1]['o1'] < r[1]['o2'] :
        short_long_signal.append(-1)#sell
        while  short_long_signal.append(-1) and  r[1]['a'] < r[1]['b']:
                 short_long_signal.append(1)#buy if sold
         
    else:
        short_long_signal.append(0)#do nothing
Pages: 1 2