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.
Clodoaldo Neto
127k30 gold badges251 silver badges274 bronze badges
1 Answer 1
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.
Sign up to request clarification or add additional context in comments.
Comments
default