Introduction to Python
Rajesh Rajamani
About Author
15 years Industry experience as a Solutions
Consultant with a leading BPO .Providing
Business Intelligence , Analytics and Software
Development consulting to clients across the
globe and across business verticals .
Professional Experience
▪ Cognitive Intelligence
▪ Coding
▪ Data Exploration
▪ Solving Real world problems with right mix
of technology
Pursuits
• Masters Degree in Computer
Applications
• Certified Hadoop Developer
• Six Sigma Green Belt
Academics rajesh.r6r@gmail.com
+91 98199 37639
rajeshr6r
What do they have in common ?
Raspberry Pi Zero Android Phone Mac book Windows Laptop
Each of these devices run a different operating system. Yet you can write a Python script with
one of these devices and run it across all of them. Truly cross platform .
Sounds cool right ?
Python – An Evolution Timeline
1989
2000
1994
2008
Created by
Guido Van Rossum
Python 1.0 released Python 2.0 released Python 3.0 released
Fun Fact : Java was introduced by Sun Microsystems in the year 1995
Reference : https://www.wikiwand.com/en/Java_(programming_language)
The Zen of Python
Reference : https://www.python.org/dev/peps/pep-0020/
1. Beautiful is better than ugly.
2. Explicit is better than implicit.
3. Simple is better than complex.
4. Complex is better than complicated.
5. Flat is better than nested.
6. Sparse is better than dense.
7. Readability counts.
8. Special cases aren't special enough to break the rules.
9. Although practicality beats purity.
10.Errors should never pass silently.
11.Unless explicitly silenced.
12.In the face of ambiguity, refuse the temptation to guess.
13.There should be one-- and preferably only one --obvious way to do it.
14.Although that way may not be obvious at first unless you're Dutch.
15.Now is better than never.
16.Although never is often better than *right* now.
17.If the implementation is hard to explain, it's a bad idea.
18.If the implementation is easy to explain, it may be a good idea.
19.Namespaces are one honking great idea -- let's do more of those!
Lets get serious
The almighty “Hello World”
Do more with less .
Python 3.x Java
Reference : https://pythonconquerstheuniverse.wordpress.com/2009/10/03/python-java-a-side-by-side-comparison/
Begone the curly braces
Python uses white space and indentation to improve readability
Like human Python interprets that an indented line is a subset of the previous un-indented line
Visual Basic Java Python
Documentation
“”” – Three successive double quotes start and end a multi-line comment
# - Denotes a single line comment
Python Data Structures
Class Description Example Mutable
bool Boolean Value True / False No
int integer 9223372036854775807 No
float floating point number 3.145 No
str string 'this is a string' No
tuple immutable sequence of objects (1,2,3,4) No
frozenset immutable form of set class frozenset({1, 2, 3, 4}) No
set unordered set of distinct objects {1,2,3}
dict dictionary {'a':1,'b':1,'c':1}
list mutable sequence of objects ['a',1,['j','k','l']]
The maximum size of the integer differs based on the system architecture .
Verify it with sys.maxsize
Reference : https://en.wikibooks.org/wiki/Python_Programming/Data_Types
Python Data Structures
mylist = list ([ 'a' , 1 , 3.14 , {'a':1 , 'b' : 1} ,{'a','b','c'} ])
List :
Output:
Methods:
Dictionary:
mydict = { 'a':'a','b':1,'c':{'a':1,'b':1},'d':{'a','b','c’} }
mydict=dict(zip(['a','b','c','d'],['a',1,{'a':1,'b':1},{'a','b','c'}]))
Output:
Methods:
Python Data Structures
Set Tuple
myset=set(['a','b','c','a'])
Output:
Methods:
Set : Frozenset :
A variant of set called frozenset are immutable
mytuple=tuple(['a','b','c','d','a'])
Output:
Methods:
To think : What is the difference between a frozenset and tuple ?. Both are immutable . Then why we have two different structs
Collections in Python
Reference :: https://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747
Anonymous functions
They’re cool. Anonymous functions are referenced by the keyword lambda.
lambda
filter map reduce
Getting square root with a custom function Getting square root with a lambda function
To get items that are divisible by 3 To square items that are multiples of 4 Sum of numbers passed in a list
A Challenge : Can we design a named function to sum a list of numbers and return the value ?
A primer on Data Science
Data Science is a discipline that provides solutions to ( but not limited to ) the following
1. Data Extraction
2. Pre-Processing
3. Identifying insights and patterns from data
4. Detect the relationships between variables and bind them together to detect an outcome.
5. Develop Models with all of the above and predict almost everything where there is enough data to train.
Reference : https://economictimes.indiatimes.com/jobs/indias-demand-for-data-scientists-grows-over-400-report/articleshow/64930355.cms
https://qz.com/india/1297493/india-has-the-most-number-of-data-analytics-jobs-after-us/
What news media says about Data Scientists
01
02
03
04
Data Pre-Processing
Visualization
Data Engineering
Machine / Deep
Learning
pandas
nltk
data cleaner
arrow
pandas
nltk
data cleaner
arrow
bokeh
matplotlib
seaborn
bokeh
matplotlib
seaborn
pandas
keras.preprocessing
dora
pandas
keras.preprocessing
dora
scikit
tensorflow
pytorch
scikit
tensorflow
pytorch
Python in Data Science Streams of Industry
Python Universe
Area Packages / Software Reference URL Usage
Data Exploration Pandas https://pandas.pydata.org/ Pandas is a powerful data exploration library. Widely
used by data scientists and integrators to make sense
of data in a matter of minutes.
Visualization Matplotlib
Seaborn
Altair
https://matplotlib.org/
https://seaborn.pydata.org/
https://altair-viz.github.io/
There are quite a few .But these can give you a good
start.
Web Scraping BeautifulSoup
Scrapy
https://www.crummy.com/software/BeautifulSoup/doc
https://scrapy.org/
Go ahead and extract html content from that favorite
shopping website of yours and find out interesting
insights
Web Automation Selenium https://selenium-python.readthedocs.io/ Login to your favorite website with selenium and then
scrape data with Beautiful Soup !!
Machine
Learning
Scikit learn https://scikit-learn.org/ Do some fabulous stuff with Machine Learning with
scikit
Cross Platform
UI Development
Kivy https://kivy.org/ Impress everyone by developing cool UI . Code Once
Deploy Everywhere .
Deep Learning Tensorflow
PyTorch
Keras
https://www.tensorflow.org/
https://pytorch.org/
https://keras.io/
Teach your machine to translate speech , write an
essay , identify whether a photo shown to it is yours
and many more with neural networks . Emulate the
Human Brain
“Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.” – Albert Einstein
Visualization of reviews in shiksha.com with
beautifulsoup,matplotlib and pandas
Reference : https://www.shiksha.com/college/vidyalankar-institute-of-technology-wadala-mumbai-35990
Download this lesson from this URL
A Cool Python Functionality
How many lines of code it would take to create a file server which has a web interface where
all the files are accessible on a web- browser like this ?
Thank you

Introduction to python

  • 1.
  • 2.
    About Author 15 yearsIndustry experience as a Solutions Consultant with a leading BPO .Providing Business Intelligence , Analytics and Software Development consulting to clients across the globe and across business verticals . Professional Experience ▪ Cognitive Intelligence ▪ Coding ▪ Data Exploration ▪ Solving Real world problems with right mix of technology Pursuits • Masters Degree in Computer Applications • Certified Hadoop Developer • Six Sigma Green Belt Academics rajesh.r6r@gmail.com +91 98199 37639 rajeshr6r
  • 3.
    What do theyhave in common ? Raspberry Pi Zero Android Phone Mac book Windows Laptop Each of these devices run a different operating system. Yet you can write a Python script with one of these devices and run it across all of them. Truly cross platform . Sounds cool right ?
  • 4.
    Python – AnEvolution Timeline 1989 2000 1994 2008 Created by Guido Van Rossum Python 1.0 released Python 2.0 released Python 3.0 released Fun Fact : Java was introduced by Sun Microsystems in the year 1995 Reference : https://www.wikiwand.com/en/Java_(programming_language)
  • 5.
    The Zen ofPython Reference : https://www.python.org/dev/peps/pep-0020/ 1. Beautiful is better than ugly. 2. Explicit is better than implicit. 3. Simple is better than complex. 4. Complex is better than complicated. 5. Flat is better than nested. 6. Sparse is better than dense. 7. Readability counts. 8. Special cases aren't special enough to break the rules. 9. Although practicality beats purity. 10.Errors should never pass silently. 11.Unless explicitly silenced. 12.In the face of ambiguity, refuse the temptation to guess. 13.There should be one-- and preferably only one --obvious way to do it. 14.Although that way may not be obvious at first unless you're Dutch. 15.Now is better than never. 16.Although never is often better than *right* now. 17.If the implementation is hard to explain, it's a bad idea. 18.If the implementation is easy to explain, it may be a good idea. 19.Namespaces are one honking great idea -- let's do more of those!
  • 6.
    Lets get serious Thealmighty “Hello World” Do more with less . Python 3.x Java Reference : https://pythonconquerstheuniverse.wordpress.com/2009/10/03/python-java-a-side-by-side-comparison/
  • 7.
    Begone the curlybraces Python uses white space and indentation to improve readability Like human Python interprets that an indented line is a subset of the previous un-indented line Visual Basic Java Python
  • 8.
    Documentation “”” – Threesuccessive double quotes start and end a multi-line comment # - Denotes a single line comment
  • 9.
    Python Data Structures ClassDescription Example Mutable bool Boolean Value True / False No int integer 9223372036854775807 No float floating point number 3.145 No str string 'this is a string' No tuple immutable sequence of objects (1,2,3,4) No frozenset immutable form of set class frozenset({1, 2, 3, 4}) No set unordered set of distinct objects {1,2,3} dict dictionary {'a':1,'b':1,'c':1} list mutable sequence of objects ['a',1,['j','k','l']] The maximum size of the integer differs based on the system architecture . Verify it with sys.maxsize Reference : https://en.wikibooks.org/wiki/Python_Programming/Data_Types
  • 10.
    Python Data Structures mylist= list ([ 'a' , 1 , 3.14 , {'a':1 , 'b' : 1} ,{'a','b','c'} ]) List : Output: Methods: Dictionary: mydict = { 'a':'a','b':1,'c':{'a':1,'b':1},'d':{'a','b','c’} } mydict=dict(zip(['a','b','c','d'],['a',1,{'a':1,'b':1},{'a','b','c'}])) Output: Methods:
  • 11.
    Python Data Structures SetTuple myset=set(['a','b','c','a']) Output: Methods: Set : Frozenset : A variant of set called frozenset are immutable mytuple=tuple(['a','b','c','d','a']) Output: Methods: To think : What is the difference between a frozenset and tuple ?. Both are immutable . Then why we have two different structs
  • 12.
    Collections in Python Reference:: https://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747
  • 13.
    Anonymous functions They’re cool.Anonymous functions are referenced by the keyword lambda. lambda filter map reduce Getting square root with a custom function Getting square root with a lambda function To get items that are divisible by 3 To square items that are multiples of 4 Sum of numbers passed in a list A Challenge : Can we design a named function to sum a list of numbers and return the value ?
  • 14.
    A primer onData Science Data Science is a discipline that provides solutions to ( but not limited to ) the following 1. Data Extraction 2. Pre-Processing 3. Identifying insights and patterns from data 4. Detect the relationships between variables and bind them together to detect an outcome. 5. Develop Models with all of the above and predict almost everything where there is enough data to train. Reference : https://economictimes.indiatimes.com/jobs/indias-demand-for-data-scientists-grows-over-400-report/articleshow/64930355.cms https://qz.com/india/1297493/india-has-the-most-number-of-data-analytics-jobs-after-us/ What news media says about Data Scientists
  • 15.
    01 02 03 04 Data Pre-Processing Visualization Data Engineering Machine/ Deep Learning pandas nltk data cleaner arrow pandas nltk data cleaner arrow bokeh matplotlib seaborn bokeh matplotlib seaborn pandas keras.preprocessing dora pandas keras.preprocessing dora scikit tensorflow pytorch scikit tensorflow pytorch Python in Data Science Streams of Industry
  • 16.
    Python Universe Area Packages/ Software Reference URL Usage Data Exploration Pandas https://pandas.pydata.org/ Pandas is a powerful data exploration library. Widely used by data scientists and integrators to make sense of data in a matter of minutes. Visualization Matplotlib Seaborn Altair https://matplotlib.org/ https://seaborn.pydata.org/ https://altair-viz.github.io/ There are quite a few .But these can give you a good start. Web Scraping BeautifulSoup Scrapy https://www.crummy.com/software/BeautifulSoup/doc https://scrapy.org/ Go ahead and extract html content from that favorite shopping website of yours and find out interesting insights Web Automation Selenium https://selenium-python.readthedocs.io/ Login to your favorite website with selenium and then scrape data with Beautiful Soup !! Machine Learning Scikit learn https://scikit-learn.org/ Do some fabulous stuff with Machine Learning with scikit Cross Platform UI Development Kivy https://kivy.org/ Impress everyone by developing cool UI . Code Once Deploy Everywhere . Deep Learning Tensorflow PyTorch Keras https://www.tensorflow.org/ https://pytorch.org/ https://keras.io/ Teach your machine to translate speech , write an essay , identify whether a photo shown to it is yours and many more with neural networks . Emulate the Human Brain “Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.” – Albert Einstein
  • 17.
    Visualization of reviewsin shiksha.com with beautifulsoup,matplotlib and pandas Reference : https://www.shiksha.com/college/vidyalankar-institute-of-technology-wadala-mumbai-35990
  • 18.
    Download this lessonfrom this URL
  • 19.
    A Cool PythonFunctionality How many lines of code it would take to create a file server which has a web interface where all the files are accessible on a web- browser like this ?
  • 20.