Python Psycopg - copy_expert with Pandas Dataframe

Viewed 70

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 Answers
Related