7.3.3 データベースからローカルPythonセッションへのデータのプル

omlプロキシ・オブジェクトのpullメソッドを使用して、ローカルPythonセッションにPythonオブジェクトを作成します。

ノート:

データをローカルのpandas.DataFrameにプルできるのは、そのデータがローカルのPythonセッション・メモリーに収まる場合のみです。また、データがメモリーに収まったとしても、非常に大きい場合は、多くの、またはすべてのPython関数をローカルPythonセッションで実行できないことがあります。

例7-9 ローカル・メモリーへのデータのプル

この例では、irisデータセットをロードし、IRISデータベース表およびその表を参照するoml_irisプロキシ・オブジェクトを作成します。oml_irisオブジェクトの型を表示し、そのオブジェクトからローカル・メモリー内のirisオブジェクトにデータをプルして、その型を表示します。


import oml
from sklearn.datasets import load_iris
import pandas as pd

iris = load_iris()
x = pd.DataFrame(iris.data, columns = [‘SEPAL_LENGTH’,‘SEPAL_WIDTH’, ‘PETAL_LENGTH’,‘PETAL_WIDTH’])
y = pd.DataFrame(list(map(lambda x: {0: ‘setosa’, 1: ‘versicolor’, 2:‘virginica’}[x], iris.target)), columns = [‘SPECIES’])
iris_df = pd.concat([x, y], axis=1)

oml_iris = oml.create(iris_df, table = ‘IRIS’)

# Display the data type of oml_iris.
type(oml_iris)

# Pull the data from oml_iris into local memory.
iris = oml_iris.pull()

# Display the data type of iris.
type(iris)

# Drop the IRIS database table.
oml.drop('IRIS')

この例のリスト

>>> import oml
>>> from sklearn.datasets import load_iris
>>> import pandas as pd
>>>
>>> # Load the iris data set and create a pandas.DataFrame for it.
>>> iris = datasets.load_iris()

>>> iris = load_iris()
>>> x = pd.DataFrame(iris.data, columns = [‘SEPAL_LENGTH’,‘SEPAL_WIDTH’, ‘PETAL_LENGTH’,‘PETAL_WIDTH’])
>>> y = pd.DataFrame(list(map(lambda x: {0: ‘setosa’, 1: ‘versicolor’, 2:‘virginica’}[x], iris.target)), columns = [‘SPECIES’])
>>> iris_df = pd.concat([x, y], axis=1)

>>> oml_iris = oml.create(iris_df, table = ‘IRIS’)

>>>
>>> # Display the data type of oml_iris.
... type(oml_iris)
<class 'oml.core.frame.DataFrame'>
>>>
>>> # Pull the data from oml_iris into local memory.
... iris = oml_iris.pull()
>>>
>>> # Display the data type of iris.
... type(iris)
<class 'pandas.core.frame.DataFrame'>
>>>
>>> # Drop the IRIS database table.
... oml.drop('IRIS')