Db to Panda¶

Loading the required libraries

In [1]:
import gstlearn as gl
import pandas as pd
import numpy as np

We first create the Data Base 'db' with few samples and 4 variables.

In [2]:
ndat = 10
db = gl.Db.create()
np.random.seed(123)
db["long"]  = np.random.uniform(size = ndat)
db["lat"]  = np.random.uniform(size = ndat)
db["z"]   = np.random.normal(size = ndat)
db["sel"] = np.random.binomial(1, 0.5, size = ndat)

Each of these variables is assigned a Locator.

In [3]:
db.setLocators(["l*"], gl.ELoc.X)
db.setLocators(["z"], gl.ELoc.Z)
db.setLocators(["sel"], gl.ELoc.SEL)

The next printout shows the contents of the Db using gstlearn format

In [4]:
db
Out[4]:
Data Base Characteristics
=========================

Data Base Summary
-----------------
File is organized as a set of isolated points
Space dimension              = 2
Number of Columns            = 4
Total number of samples      = 10
Number of active samples     = 3

Variables
---------
Column = 0 - Name = long - Locator = x1
Column = 1 - Name = lat - Locator = x2
Column = 2 - Name = z - Locator = z1
Column = 3 - Name = sel - Locator = sel

We now convert it into a Panda file

In [5]:
dat = db.toTL()

We check its contents using Panda own format

In [6]:
dat
Out[6]:
long lat z sel
0 0.696469 0.343178 1.004054 0.0
1 0.286139 0.729050 0.386186 0.0
2 0.226851 0.438572 0.737369 0.0
3 0.551315 0.059678 1.490732 0.0
4 0.719469 0.398044 -0.935834 0.0
5 0.423106 0.737995 1.175829 0.0
6 0.980764 0.182492 -1.253881 0.0
7 0.684830 0.175452 -0.637752 1.0
8 0.480932 0.531551 0.907105 1.0
9 0.392118 0.531828 -1.428681 1.0

The conversion is performed once more, but keeping track of the locator information assigned to each variable.

In [7]:
dat = db.toTL(True)

The printout is not modified.

In [8]:
dat
Out[8]:
long lat z sel
0 0.696469 0.343178 1.004054 0.0
1 0.286139 0.729050 0.386186 0.0
2 0.226851 0.438572 0.737369 0.0
3 0.551315 0.059678 1.490732 0.0
4 0.719469 0.398044 -0.935834 0.0
5 0.423106 0.737995 1.175829 0.0
6 0.980764 0.182492 -1.253881 0.0
7 0.684830 0.175452 -0.637752 1.0
8 0.480932 0.531551 0.907105 1.0
9 0.392118 0.531828 -1.428681 1.0

But each variable can show the locator which is attached to it. The syntax is as follows:

In [9]:
dat.sel.locator
Out[9]:
'sel'