tables module

class pycax.tables.TablesResponse(tablename, args)[source]

A tables Response Object

Usage

from pycax import tables

query = tables.get("NOSA", qargs={'limit': 2})
query.execute()
query.data  # Returns the data
query.api_url  # Returns the API URL
query.to_pandas()  # Returns a pandas DataFrame

# Download one record as a data frame
df = tables.getdf("NOSA", qargs={'limit': 1})
id = df['popid'][0]
# Download a data frame using a filter. Here only return popid = 7
filt = {'popid': id}
df = tables.getdf("NOSA", fargs=filt)

Methods:

pycax.tables.get(tablename, qargs={}, fargs={}, **kwargs)[source]

Get a table using the table name from /ca/tables API

Parameters:
  • tablename – [String] A table name listed in the datasets table

  • qargs – [dict] a dictionary of query parameters. The default is no parameters. See usage for common query parameters

  • fargs – [dict] a dictionary of filter values as {colname1: value}, {colname1: [value1, value2]} or {colname1: value, colname2: value}. The default is no filter. See usage for examples.

Returns:

A dictionary of class TableResponse ready for execution

Usage:

from pycax import tables
query = tables.get('EscData', qargs={'limit': 1})
query.execute()
query.data # get the data
query.api_url # get the API url
pycax.tables.getdf(tablename, qargs={}, fargs={}, **kwargs)[source]

Make table query and return a pandas DataFrame

Parameters:
  • qargs – [dict] a dictionary of query parameters. The default is no parameters which returns the full table.

  • fargs – [dict] a dictionary of filter values as {colname1: value}, {colname1: [value1, value2]} or {colname1: value, colname2: value}. The default is no filter. See usage for examples.

Returns:

A pandas DataFrame

Usage:

from pycax import tables
tables.getdf('EscData')
pycax.tables.tableid(tablename)[source]

Retrieve a table id given a tablename

Parameters:

tablename – [String] table name from pycax.tables.getdf()[“name”]

Returns:

A table id as an array of length 1 with id as a string

Usage:

from pycax import tables
tables.tableid("NOSA")
pycax.tables.dict_to_json(fargs)[source]

Convert a dictionary to JSON format for CAX API: field, value, string format

Parameters:

fargs – [dict] a dictionary of filter values as {colname1: value}, {colname1: [value1, value2]} or {colname1: value, colname2: value}. The default is no filter. See usage for examples.

Returns:

JSON for the filter in the format that CAX API wants: ‘[{“field”: “popid”, “value”: 7, “type”: “string”}]’

Usage:

from pycax import tables
tables.dict_to_json({'popid':7})