How to prevent a for loop from stopping?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Loop through an array in JavaScriptHow do I list all files of a directory?Iterating over dictionaries using 'for' loops
How to win an all out war against ants
How to design an effective polearm-bow hybrid?
Speaker impedance: rewiring four 8 Ω speakers for use with 8 Ω amp output
What is a summary of basic Jewish metaphysics or theology?
Generate random number in Unity without class ambiguity
Astable 555 circuit not oscillating
Does a bard know when a character uses their Bardic Inspiration?
Skipping same old introductions
How does shared_ptr<void> know which destructor to use?
Reasons for using monsters as bioweapons
How to enable/disable Adobe host port in terminal?
Have you been refused entry into the Federal Republic of Germany?
How to call made-up data?
Is it moral to remove/hide certain parts of a photo, as a photographer?
Confused over role of 「自分が」in this particular passage
A wiild aanimal, a cardinal direction, or a place by the water
Difference between "jail" and "prison" in German
What is the most 'environmentally friendly' way to learn to fly?
How were x-ray diffraction patterns deciphered before computers?
How can I perform a deterministic physics simulation?
Why adjustbox needs a tweak of raise=-0.3ex with enumitem?
Being told my "network" isn't PCI compliant. I don't even have a server! Do I have to comply?
Why have both: BJT and FET transistors on IC output?
Partial Fractions: Why does this shortcut method work?
How to prevent a for loop from stopping?
How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Loop through an array in JavaScriptHow do I list all files of a directory?Iterating over dictionaries using 'for' loops
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue
statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.
If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.
I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
continue
return sell-buy
gains = checking(volume,close)
gains
I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.
python pandas loops for-loop
add a comment |
In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue
statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.
If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.
I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
continue
return sell-buy
gains = checking(volume,close)
gains
I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.
python pandas loops for-loop
add a comment |
In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue
statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.
If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.
I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
continue
return sell-buy
gains = checking(volume,close)
gains
I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.
python pandas loops for-loop
In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue
statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.
If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.
I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
continue
return sell-buy
gains = checking(volume,close)
gains
I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.
python pandas loops for-loop
python pandas loops for-loop
edited Mar 27 at 2:58
Pikachu the Parenthesis Wizard
2,1668 gold badges17 silver badges29 bronze badges
2,1668 gold badges17 silver badges29 bronze badges
asked Mar 27 at 1:32
Guillermo CampolloGuillermo Campollo
82 bronze badges
82 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You're right, the indentation of the return statement was incorrect. Here's the fixed code:
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
add a comment |
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368508%2fhow-to-prevent-a-for-loop-from-stopping%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're right, the indentation of the return statement was incorrect. Here's the fixed code:
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
add a comment |
You're right, the indentation of the return statement was incorrect. Here's the fixed code:
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
add a comment |
You're right, the indentation of the return statement was incorrect. Here's the fixed code:
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
You're right, the indentation of the return statement was incorrect. Here's the fixed code:
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
answered Mar 27 at 1:43
Artemis FowlArtemis Fowl
1,6934 gold badges13 silver badges28 bronze badges
1,6934 gold badges13 silver badges28 bronze badges
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
add a comment |
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
@GuillermoCampollo If an answer solves your problem, you can upvote and accept it.
– Artemis Fowl
Mar 27 at 2:36
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again
– Guillermo Campollo
Mar 28 at 14:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
@GuillermoCampollo See What is reputation? and Upvote privilege.
– Artemis Fowl
Mar 28 at 15:24
add a comment |
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
add a comment |
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
add a comment |
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]
return sell-buy
gains = checking(volume,close)
answered Mar 27 at 1:44
Suven PandeySuven Pandey
6713 silver badges16 bronze badges
6713 silver badges16 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368508%2fhow-to-prevent-a-for-loop-from-stopping%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown