Current version:
disabled

Jupyter example for BailamAPI

This notebook illustrates how to use Bailam learning server to generate code autoamtically

setup

idle
Defaulting to user installation because normal site-packages is not writeable
Collecting git+https://gitlab.com/kamouno/bailam_api@develop
  Cloning https://gitlab.com/kamouno/bailam_api (to revision develop) to /tmp/pip-req-build-9vkrmc7i
  Running command git clone -q https://gitlab.com/kamouno/bailam_api /tmp/pip-req-build-9vkrmc7i
  Resolved https://gitlab.com/kamouno/bailam_api to commit 1ad8219fc4ec2f240781eed589c3a28a234f183e
Requirement already satisfied: pandas in /usr/local/lib/python3.7/site-packages (from bailamapi==0.1a2) (1.3.4)
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (from bailamapi==0.1a2) (2.26.0)
Requirement already satisfied: xlrd in /app/.local/lib/python3.7/site-packages (from bailamapi==0.1a2) (2.0.1)
Requirement already satisfied: openpyxl in /app/.local/lib/python3.7/site-packages (from bailamapi==0.1a2) (3.0.9)
Requirement already satisfied: et-xmlfile in /app/.local/lib/python3.7/site-packages (from openpyxl->bailamapi==0.1a2) (1.1.0)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/site-packages (from pandas->bailamapi==0.1a2) (2021.3)
Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.7/site-packages (from pandas->bailamapi==0.1a2) (1.21.3)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/site-packages (from pandas->bailamapi==0.1a2) (2.8.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas->bailamapi==0.1a2) (1.16.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests->bailamapi==0.1a2) (3.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests->bailamapi==0.1a2) (1.26.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests->bailamapi==0.1a2) (2021.10.8)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.7/site-packages (from requests->bailamapi==0.1a2) (2.0.7)
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
idle

Source and target data

The sourec and target data can be any Dataframe. The source datafrane source_df contsins the data to be transformed, the target dataframe target_df contains results for some lines of the source

idle
idle
id age name country citizen year
0 a1 2 david US US 2021
1 a2 5 johN FR FR 2021
2 a3 10 Jhony FR IL 2021
3 a4 20 Noa IL CH 2021
4 a5 11 Yousouf CH CH 2021
idle
id nom native cty birth_year oldy
0 a1 DAVID YES USA 2019 4
1 a2 JOHN YES FRA 2016 10
2 a3 JOHNY NO FRA 2011 20
idle

Details of the system link can be view using the link below (use your username or test_public/BailamPublic)

idle
https://app.bailam.com/smartmap/1690/smart-link/
idle
id nom native cty birth_year oldy
0 a1 david YES USA 2019 4
1 a2 johN YES FRA 2016 10
2 a3 Jhony NO FRA 2011 20
3 a4 Noa NO ISR 2001 40
4 a5 Yousouf YES CHE 2010 22
idle
# Parameters used for generation: 
#  function_name = transform 
#  add_include_string = True 
#  add_try_catch = False 
#  strength_limit = 30 


def transform(datasource):

	 # ----- Helper Functions Section ----- 

	def is_equal(data1, data2):
	    try:
	        return data1 == data2
	    except:
	        return 'comparison error'


	def toUpper(Text):
	    return str(Text).upper()


	def subtraction(data1, data2):
	    return data1 - data2


	def addition(data1, data2):
	    return data1 + data2


	 # ----- Main Code Section ----- 

	import pandas as pd 
	resultDF = pd.DataFrame()
	OD=dict()
	for J in datasource.iterrows() :
		I=J[1]
		O=dict()

		# generated by BasicMapper  strength : 96.38

		O['id'] = I['id']

		# generated by MappingFuzzy  strength : 68.89

		O['nom'] = I['name']

		# generated by MappingBooleanGenerator  strength : 41.87

		if is_equal(I['citizen'], I['country']) == True:
			O['native'] = 'YES'
		else:
			O['native'] = 'NO'

		# generated by BasicMappingDictionary  strength : 89.97

		if toUpper(I['country']) == 'AF':
			O['cty'] = 'AFG'
		elif toUpper(I['country']) == 'AX':
			O['cty'] = 'ALA'
		elif toUpper(I['country']) == 'AL':
			O['cty'] = 'ALB'
		elif toUpper(I['country']) == 'DZ':
			O['cty'] = 'DZA'
		elif toUpper(I['country']) == 'AS':
			O['cty'] = 'ASM'
		elif toUpper(I['country']) == 'AD':
			O['cty'] = 'AND'
		elif toUpper(I['country']) == 'AO':
			O['cty'] = 'AGO'
		elif toUpper(I['country']) == 'AI':
			O['cty'] = 'AIA'
		elif toUpper(I['country']) == 'AQ':
			O['cty'] = 'ATA'
		elif toUpper(I['country']) == 'AG':
			O['cty'] = 'ATG'
		elif toUpper(I['country']) == 'AR':
			O['cty'] = 'ARG'
		elif toUpper(I['country']) == 'AM':
			O['cty'] = 'ARM'
		elif toUpper(I['country']) == 'AW':
			O['cty'] = 'ABW'
		elif toUpper(I['country']) == 'AU':
			O['cty'] = 'AUS'
		elif toUpper(I['country']) == 'AT':
			O['cty'] = 'AUT'
		elif toUpper(I['country']) == 'AZ':
			O['cty'] = 'AZE'
		elif toUpper(I['country']) == 'BS':
			O['cty'] = 'BHS'
		elif toUpper(I['country']) == 'BH':
			O['cty'] = 'BHR'
		elif toUpper(I['country']) == 'BD':
			O['cty'] = 'BGD'
		elif toUpper(I['country']) == 'BB':
			O['cty'] = 'BRB'
		elif toUpper(I['country']) == 'BY':
			O['cty'] = 'BLR'
		elif toUpper(I['country']) == 'BE':
Load more content

You can create a local python function as below and then use it directly

idle
idle
id nom native cty birth_year oldy
0 a1 david YES USA 2019 4
1 a2 johN YES FRA 2016 10
2 a3 Jhony NO FRA 2011 20
3 a4 Noa NO ISR 2001 40
4 a5 Yousouf YES CHE 2010 22
idle

You can also apply mapping function as below, if you have updated the mapping on the website it will use the lates version

idle
id nom native cty birth_year oldy
0 a1 david YES USA 2019 4
1 a2 johN YES FRA 2016 10
2 a3 Jhony NO FRA 2011 20
3 a4 Noa NO ISR 2001 40
4 a5 Yousouf YES CHE 2010 22

You can also apply have the mapping executed on the srver and create a mapping process :

idle
Unnamed: 0 id nom native cty birth_year oldy
0 0 a1 david YES USA 2019 4
1 1 a2 johN YES FRA 2016 10
2 2 a3 Jhony NO FRA 2011 20
3 3 a4 Noa NO ISR 2001 40
4 4 a5 Yousouf YES CHE 2010 22
idle
Loading...