Back to Community
Fundamentals Query

I'm only a novice at coding in python and am having a few issues with dataframes. I have 30 stocks in my universe and wish to assign them each two extra variables a and b (where a will be equal to either 80 or 900 and b will be equal to either 40 or 1500) which will be determined by whether the ROE for that company is above or below 0.3. So far the dataframe is working fine and the ROE variable defined in my code is returning a series of 30 values as expected. I am struggling to understand why I can't seem to define two new series "a" and "b" could please give some guidance, thanks in advance. Here is my attempt at trying to define series a and b.


while n 0.3:
n += 1

1 response

I'm struggling a little bit to understand what you are trying to do but I'll give you a general example and hopefully you can go from there. Defining pandas Series are very similar to defining a dictionary in python. I like to do something like this when I am iteratively adding values to a Series...

import pandas as pd

my_series = pd.Series()  
for security in collection_of_securities:  
    my_series[security] = "Hello World!"  

Now my_series is a Pandas Series contain the value "Hello World!" for each security. Check out the Pandas Docs for more detailed explanations of the Series object.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.