#๐Ÿ”’ Does the logic make sense, along with the syntax for this loop?

27 messages ยท Page 1 of 1 (latest)

ruby halo
#
dropping_indices = []
for index, row in df_2019.iterrows():
    if ((row['color'] == 'green') & (row['volatility'] < 10 * row['mean_return'])) or (row['color'] == 'red') & (row['volatility'] >= 10 * row['mean_return']) :
        dropping_indices.append(index)
        print(row['volatility'])
        print(row['mean_return'])
    else:
        continue

df_2019.drop(dropping_indices, inplace=True)

I'm not sure if it is catching anything, but it is definitely changing my matplotlib scatter plot

crystal locustBOT
#

@ruby halo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

little swift
#

also else: continue isn't required in this case, because there is no code to skip after that line

little swift
ruby halo
ruby halo
# little swift I can't determine if you logic is correct unless I know what it is supposed to d...

This is the full code snippet:

#I've decided my slope is y=10x, which means its starts at (0,0) and stretches all the way to (.6,6). Anything to the 
#right of that is accepted, to the left marked as a 'NO BUY'



dropping_indices = []
for index, row in df_2019.iterrows():
    if ((row['color'] == 'green') & (row['volatility'] < 10 * row['mean_return'])) or (row['color'] == 'red') & (row['volatility'] >= 10 * row['mean_return']) :
        dropping_indices.append(index)
        print(row['volatility'])
        print(row['mean_return'])
    else:
        continue
df_2019.drop(dropping_indices, inplace=True)

plt.title('Scatter Plot for Mean and Volatility')
plt.xlabel('Mean')
plt.ylabel('Standard Deviation')
plt.scatter(df_2019['mean_return'], df_2019['volatility'], c=df_2019['color'])
plt.legend()
plt.grid(True)
plt.show()
ruby halo
#

Anything to the left that is green needs to be dropped, everything to the right as red as well

little swift
#

!e print(bin(0b0110 & 0b1101))

crystal locustBOT
#

@little swift :white_check_mark: Your 3.12 eval job has completed with return code 0.

0b100
ruby halo
#

when does one use '&' instead?

little swift
#

& is only working there because True == 1

little swift
#
  0110
& 1101
-------
  0100
#

take 1 if both are 1 else 0 for each bit

#

it only works in your case because True == 1

ruby halo
#

OH i see

little swift
#

instead you should use logical and, which is and

#

same how you did or

#

there is also bitwise or, |

little swift
#

else: continue can be omitted

ruby halo
crystal locustBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.