1

I tried to read postgres array from pandas like so:

import pandas as pd
import psycopg2 as pg
con = pg.connect(con_info)
df = pd.read_sql(con,'select my_arr from my_table')

however what i'm getting is a string like so:

 my_arr
 ---------
'{1,2,3}'

I can parse the string, but I want to get it without any string manipulation as a python list.

thanks.

joseph.

1 Answer 1

0

found one answer, using array_to_json solves this.

Convert PostgreSQL array to PHP array in python:

df = pd.read_sql(con,'select array_to_json(my_arr) from my_table')

the datatype in the column is a python list. However, I wonder if there is a more natural way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.