Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 5dfe5f0

Browse files
authored
Merge pull request #386 from IntelPython/new_sdc_examples
Refactored Examples. Old examples are moved under old_examples folder…
2 parents 430d377 + daa5cac commit 5dfe5f0

26 files changed

Lines changed: 292 additions & 28 deletions

examples/basic_workflow.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2019, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
# Dataset for analysis
31+
FNAME = "employees.csv"
32+
33+
34+
# This function gets compiled by Numba*
35+
@njit
36+
def get_analyzed_data():
37+
df = pd.read_csv(FNAME)
38+
s_bonus = pd.Series(df['Bonus %'])
39+
s_first_name = pd.Series(df['First Name'])
40+
m = s_bonus.mean()
41+
names = s_first_name.sort_values()
42+
return m, names
43+
44+
45+
# Printing names and their average bonus percent
46+
mean_bonus, sorted_first_names = get_analyzed_data()
47+
print(sorted_first_names)
48+
print('Average Bonus %:', mean_bonus)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2019, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
# Dataset for analysis
31+
FNAME = "employees.csv"
32+
33+
34+
# This function gets compiled by Numba* and multi-threaded
35+
@njit(parallel=True)
36+
def get_analyzed_data():
37+
df = pd.read_csv(FNAME)
38+
s_bonus = pd.Series(df['Bonus %'])
39+
s_first_name = pd.Series(df['First Name'])
40+
m = s_bonus.mean()
41+
names = s_first_name.sort_values()
42+
return m, names
43+
44+
45+
# Printing names and their average bonus percent
46+
mean_bonus, sorted_first_names = get_analyzed_data()
47+
print(sorted_first_names)
48+
print('Average Bonus %:', mean_bonus)

examples/employees.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
,Gender,First Name,Start Date,Last Login Time,Salary,Bonus %,Senior Management,Team
2+
0,Female,EMILY,2015-12-04,0 days 21:41:41.000000000,39582,1.306,,Business Development
3+
1,Male,NOAH,2011-02-02,0 days 00:04:19.000000000,124742,5.881,False,Client Services
4+
2,Male,ISAAC,1994-10-25,0 days 04:35:46.000000000,138462,14.995,True,Sales
5+
3,Male,,1998-12-24,0 days 18:35:33.000000000,60661,3.477,False,Business Development
6+
4,,CHRISTOPHER,2002-03-05,0 days 12:26:32.000000000,97764,15.65,False,
7+
5,Female,MIA,2005-01-20,0 days 17:47:44.000000000,42104,12.595,False,Product
8+
6,Female,OLIVIA,1994-07-13,0 days 00:43:25.000000000,46646,1.284,False,Client Services
9+
7,Male,ALEXANDER,2019-09-03,0 days 04:15:00.000000000,123807,17.849,True,Legal
10+
8,Male,JOSEPH,2008-09-15,0 days 01:16:05.000000000,139681,19.904,False,Engineering
11+
9,Male,JOSEPH,2009-06-11,0 days 20:27:06.000000000,71359,19.103,False,Client Services

0 commit comments

Comments
 (0)