Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kernel dies when using pandas to work on dataframe from sql

my kernel dies when I try to change a dataframe with data that I get using an sql query.

I reduced the amount of data, increased my RAM and commented out code that consistently crashed the kernel.

    python
    import pandas as pd
    import sqlalchemy
    sql_str = """some sql query limit 100""" 
    df = pd.read_sql(sql_str, engine)   
    list=[
    '1st name','2nd name'] 
    for i in range(0,len(list)):
        df.columns.values[i]=list[i]
    #naming the columns of my df
    df=df[df["tradedate"]<'01-01-2017']
    #this is a line of code that sometimes crashes the kernel
    df['strike']=pd.to_numeric(df["strike"],errors='coerce')
    #another one

I expect a clean dataframe with which I can work, instead the kernel dies and I get a windows error.

I would be incredibly thankful if somebody could help me here!

like image 701
JulianGruber Avatar asked Jul 30 '26 04:07

JulianGruber


1 Answers

Try to use chunksize parameter:

df = pd.read_sql(sql_str, engine, chunksize=20) #try different values
like image 54
AT_asks Avatar answered Jul 31 '26 19:07

AT_asks