Pushing Data

[ ]:
#To get a copy of this notebook in your current working dirtectory, run:
from pycelonis import notebooks

This tutorial shows how data can be pushed from Python to Celonis. The data is pushed to a Celonis Data Model and can then be used and analyzed in an Analysis. In this to Turial we will: 1. First create an exemplary pandas data frame 2. Create the connection to the Celonis data model where we want to push the data 3. Push the data

Create a pandas dataframe.

[1]:
import pandas as pd

df = pd.DataFrame({'A': [2, 4, 8, 0], 'B': [2, 0, 0, 0], 'C': [10, 2, 1, 8]})
df.head()
[1]:
A B C
0 2 2 10
1 4 0 2
2 8 0 1
3 0 0 8

Connect to Celonis and find the data pool.

[2]:
from pycelonis import get_celonis

celonis = get_celonis()
2019-10-08 12:11:26 - Login successful! Hello Simon Riezebos
[3]:
data_pool = celonis.pools.find("f8e841e3-26f5-494a-93fd-842252aef176")
data_pool
[3]:
<Pool, id f8e841e3-26f5-494a-93fd-842252aef176, name SAP ECC - Purchase to Pay (SE HANA SolEng)>

Option 1: Push the data (data pool)

we push the data frame to the data pool. For this, we use the push_table() function, which has the following properties: * df_or_path: Either the pandas data frame or the path to a data frame that should be pushed to Celonis * table_name: The name that this data frame should have in the data pool * if_exists: Specifies what happens when the table already exists in the data pool. The options are ‘replace’, ‘append’, ‘upsert’, ‘error’

The additional parameters (like the setting of primary keys and column types) can be checked by pressing SHIFT + TAB, while the curser is in the function push_table()

[4]:
data_pool.push_table(df,"Test_Data", if_exists = 'replace')
[4]:
{'id': 'ce9e94c2-a939-4f2e-beba-b043fb1d4732',
 'targetName': 'Test_Data',
 'lastModified': 1570529501078,
 'lastPing': None,
 'status': 'DONE',
 'type': 'REPLACE',
 'fileType': None,
 'targetSchema': 'f8e841e3-26f5-494a-93fd-842252aef176',
 'dataPoolId': 'f8e841e3-26f5-494a-93fd-842252aef176',
 'connectionId': None,
 'logs': ['2019-10-08T10:11:41 - Starting execution',
  '2019-10-08T10:11:43 - Done loading chunks',
  '2019-10-08T10:11:43 - Execution done'],
 'csvParsingOptions': None,
 'tableSchema': None,
 'keys': [],
 'optionalTenantId': None}

The table is now in the data pool and can be added to any data model in that pool.

Option 2: Push the data (data model)

We could also directly push the table to the data model. We would first need to find the data model.

[5]:
data_model = celonis.datamodels.find("3f6ef2f6-6635-49de-aa8c-7090188bb78b")
data_model
[5]:
<Datamodel, id 3f6ef2f6-6635-49de-aa8c-7090188bb78b, name SAP ECC - Purchase to Pay Data Model>

… and then use the push_table() function again. Here we have additionally the option to reload the data model.

[6]:
data_model.push_table(df,"Test_Data",reload_datamodel=False, if_exists = 'replace')
[6]:
<DatamodelTable, id 1098542d-3731-4365-8174-1ea6546f5f27, name Test_Data>