有没有办法让pandas将带有数组类型列的表直接读入本机结构?默认情况下,int[]
列最终作为包含python int of python列表的对象列。系列中有ways to convert这个,或者更好,有一个多索引的列,但对于500M行来说这是非常慢的(~10秒)。如果数据最初加载到数据帧中会更快。我没有在sql中展开数组的内容,因为我有很多数组列。
url = "postgresql://u:p@host:5432/dname"
engine = sqlalchemy.create_engine(url)
df = pd.read_sql_query("select 1.0 as a, 2.2 as b, array[1,2,3] as c;", engine)
print df
print type(df.loc[0,'c']) # list
print type(df.loc[0,'c'][0]) # int