I am developing a PostgreSQL Procedure using the plpython3u extension which let you use python procedural language into PostgreSQL.
With the following code using plpy, I am able to retrive data form table and put it into pandas dataframe.
CREATE OR REPLACE PROCEDURE public.plpy_proc_clas_full(
)
LANGUAGE 'plpython3u'
AS $BODY$
import pandas as pd
data_lt = plpy.execute('SELECT "key", "value" FROM public."<your-table>" ORDER BY "key"'); #PLyResult --> List or Dictionary
data_df_x = pd.DataFrame.from_records(data_lt)['key'];
data_df_y = pd.DataFrame.from_records(data_lt)['value'];
df = pd.concat([data_df_x, data_df_y], axis=1).values
return df;
$BODY$;
But how can I write back the pandas dataframe to a table (for example after a few data manipulations in python)?