geosoft.gxpy.dataframe submodule

Table (records, fields) handling, inherits from Pandas (http://pandas.pydata.org/) base class.

Classes
Data_frame

dataframe that holds a table

Note

Regression tests provide usage examples: dataframe tests

Data_frame(initial=None, records=None, columns=None)[source]

Pandas DataFrame from a Geosoft table.

Parameters
initial

Geosoft table name, which is normally an ASCII csv file. If the table cannot be found in the project folder user/csv is searched, then the Geosoft csv folder.

records

Record name to include, or a list of records to include. If not specified all records are included in the dataframe.

columns

Column name to be included, or a list of column names to include. If not specified all columns are included in the dataframe.

Raises
DfException

if no columns.records found in the table. If only some fields are found the dataframe is created with the found fields.

raises geosoft.gxapi.GXError

if a requested record is not found.

This returns a Pandas DataFrame instance, which can be accessed and used with standard Pandas calls.

Column names from Geosoft table files are always uppercase, regardless of case used in the table file.

Record/index names from Geosoft table files are case-sensitive.

Example table file “rockcode.csv”:

/ standard Geosoft rock codes
CODE,LABEL,__DESCRIPTION,PATTERN,PAT_SIZE,PAT_DENSITY,PAT_THICKNESS,COLOR
bau,BAU,BAUXITE,100,,,,RG49B181
bif,BIF,"BANDED IRON FM",202,,,,R
cal,CAL,CALCRETE,315,,,,B
cbt,CBT,CARBONATITE,305,,,,R128G128B192
include geosoft.gxpy as gxpy
with gxpy.GXpy() as gx:
    df = gxpy.dataframe.Data_frame('rockcode')
    print(len(df))
    print(df.loc['bif', 'DESCRIPTION']) # "BANDED IRON FM"
    print(df.loc['bif'][1])             # "BANDED IRON FM"
    print(df.iloc[1,0])                 # "BIF"
    print(df.loc['cal', 'PATTERN'])     # "315"

New in version 9.2.

Changed in version 9.4.

exception DfException(message)[source]

Bases: geosoft.GXRuntimeError

Exceptions from geosoft.gxpy.dataframe.

New in version 9.2.

table_column(table, col)[source]

Return a dictionary of a column from a table

Parameters
  • table – table name

  • col – column wanted

Returns

dictionary containing record values as strings

New in version 9.2.

table_record(table, rec)[source]

Return a dictionary of a single record from a table

Parameters
  • table – table name

  • rec – record wanted

Returns

dictionary containing record values as strings

New in version 9.2.