Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete DataFrame if condition is true – Pandas

I’m sorry if this is obvious (I feels like it should be). I am downloading stock data using a for loop to create a set of dataframes labeled with the ticker name. I wish to not download stocks that return less than x rows in the downloaded data.

I currently have this that is not working?

with open('Tickers/25_tickers.csv') as f:
    lines = f.read().splitlines()

    for Symbol in lines:
        print(Symbol)
        vars()[Symbol] = pd.DataFrame()
        vars()[Symbol] = yf.download(Symbol, start, end, interval= '1d')
        i = vars()[Symbol].shape[0] #try to remove empty and low row df.
        if i > 10 == True:
                pass

When I use %whos DataFrame I get the list of ‘ticker’ DataFrames and the problem DataFrames still exist.
I’m also not sure if I should do it while downloading or after the dataframes are in.
Any help would be great. Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

with open('Tickers/25_tickers.csv') as f:
    lines = f.read().splitlines()

    for Symbol in lines:
        print(Symbol)
        vars()[Symbol] = pd.DataFrame()
        vars()[Symbol] = yf.download(Symbol, start, end, interval= '1d')
        i = vars()[Symbol].shape[0] #try to remove empty and low row df.
        if i < 10:
            del vars()[Symbol]
                
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading