1

I can't find a fancy way to use copy_expert, directly from a Dataframe.

This work perfectly:

Code

    connection = self.engine.raw_connection()
    cursor = connection.cursor()

    dir_file = ''
    with open(dir_archivo, 'r+') as f:
        cursor.copy_expert("COPY table FROM STDIN WITH CSV HEADER DELIMITER ','", f)
    connection.commit()
    cursor.close()

I would like to use copy_expert directly from a dataframe. Do i need to generate the csv?

Sorry for my bad english, and thanks!

1 Answers1

0

This works for me:

    buf = io.StringIO()

    df.to_csv(buf, index=False)

    buf.seek(0)

Get the info from: Turn pandas dataframe into a file-like object in memory?

Thanks!