1 python postgresql server-side greenplum pandas
是否可以在 greenplum 数据库中使用 pandas,如果可以,如何使用?我在greenplum里面。我正在创建一个函数:
CREATE OR REPLACE FUNCTION myfunction() RETURNS
text AS $$
...
python code
...
rv = plpy.execute("SELECT * FROM mytable")
...
$$ LANGUAGE plpythonu;
SELECT public.myfunction()
Run Code Online (Sandbox Code Playgroud)
该命令rv = plpy.execute("SELECT * FROM mytable")生成一个 PlyResult 类型的对象。现在,我想用 python pandas 来分析 rv 中的数据。如何将 rv 转换为数据帧?谢谢你!
小智 5
这是我的例子之一:
drop function if exists describe_yelp();
create or replace function describe_yelp(
OUT stats text,
OUT stars numeric,
OUT cool numeric,
OUT useful numeric,
OUT funny numeric,
OUT txt_length numeric)
returns setof record
as $$
import pandas as pd
import numpy as np
import nltk
from nltk.corpus import stopwords
yelp=pd.DataFrame.from_records(plpy.execute('select * from yelp'))[['stars','cool','useful','funny','text']]
yelp['txt_length'] = yelp['text'].apply(len)
return yelp.describe().to_records()
$$
language plpythonu;
Run Code Online (Sandbox Code Playgroud)
我的博客中有更多 Greenplum - Pandas - Numpy - 等集成的示例: https: //dwhsys.com/2018/05/06/data-mining-in-mpp-database/
| 归档时间: |
|
| 查看次数: |
1755 次 |
| 最近记录: |