Usage
The GENESIS data model
The Genesis data structure consists of multiple elements as summarized in the image below.
This package currently supports retrieving the following data types:
Tables: Main statistical objects provided by the Genesis databases.
Find the right data
pystatis
offers the Find
class to search for any piece of information within each database. Behind the scene it’s using the find
endpoint.
Example:
from pystatis import Find
results = Find("Rohöl", "genesis") # Initiates object that contains all variables, statistics, tables and cubes
results.run() # Runs the query
results.tables.df # Results for tables
results.tables.get_code([1,2,3]) # Gets the table codes, e.g. for downloading the table
results.tables.get_metadata([1,2]) # Gets the metadata for the table
A complete overview of all use cases is provided in the example notebook for find.
Download data
At the moment, the package only supports the download of Tables.
Example for downloading a Table:
from pystatis import Table
t = Table(name="21311-0001") # data is not yet downloaded
t.get_data() # only now the data is either fetched from GENESIS or loaded from cache. If the data is downloaded from online, it will be also cached, so next time the data is loaded from cache. The default language of the data is German but it can be set to either German (de) or English (en) using the language parameter of get_data().
t.data # prettified data stored as pandas DataFrame
For more details, please study the provided sample notebook for tables.
Clear Cache
When a table is queried, it will be put into cache automatically. The cache can be cleared using the following function:
from pystatis import clear_cache
clear_cache("21311-0001") # only deletes the data for the object with the specified name
clear_cache() # deletes the complete cache