1 of 43

Python Introductory Workshop

Abhimanyu Hans

Data Services Assistant at GIS and Data Labs

UMD Libraries

Link to GitHub Workshop Repository

2 of 43

Who We Are: GIS and Data Lab at UMD Libraries

3 of 43

Other Upcoming Workshops

GIS

  • ArcGIS Pro
  • ArcGIS Online and StoryMapping
  • ArcGIS Experience Builder OpenSource
  • GIS: QGIS ArcGIS Dashboards
  • Map Tour with Jim
  • Geo-AI

Data Science/Viz

  • Python
  • Tableau
  • R
  • NVivo
  • PowerBI
  • SQL

Library calendar for all workshops

4 of 43

Agenda

  1. Python Background
  2. Jupyter Notebooks
  3. Syntax Introduction

5 of 43

Attendees Survey Alert!

6 of 43

Python Background

7 of 43

Why Python?

  • Growing popularity
  • Ease of understanding and use
  • Used in variety of projects
  • Open source community => Out-of-box libraries for most things
  • Basically, perfect (first) programming language to begin with

8 of 43

TIOBE Programming Community Index

Source: https://www.tiobe.com/tiobe-index/

9 of 43

Where is Python Used

  • Data science
  • Web Development
  • Data Engineering Pipelines
  • Scientific Computing
  • ML/AI
  • Gaming

10 of 43

Python Installation

Instructions shared via email

11 of 43

Install Python

Please follow the link below to download and run the installer. We will be using the Anaconda distribution of python

  • Windows
  • MacOS
  • Others

12 of 43

Integrated Development Environment (IDEs)

  • IDEs facilitate the process of writing code into a text file
  • Includes many features such as autocomplete, syntax highlighting, linting (error detection), etc.
  • Notepad, VS Code, Jupyter Notebook, Spyder, IntelliJ, etc.

13 of 43

Jupyter Notebooks

14 of 43

Jupyter Notebooks

  • Simple and basic
  • Offers interactive code execution (hence used in data science scripts which requires explorative work)
  • Code is executed in “Cell-by-Cell” manner
  • Offers two types of cell viz.
    • Code: for python commands
    • Markdown: for documentation (like HTML)

15 of 43

Getting Started with Jupyter

16 of 43

Syntax Introduction

Running Example:

1. Solving quadratic equation

2. FizzBuzz Problem

17 of 43

Variables vs Literals

  • A Variable is a location that is named in order to store data while the program is being run
  • The data which is being assigned to the variables are called as Literal.
  • Syntax to assign literal value to a variable using assignment operator (=)

18 of 43

Basic Data Types

  • Int
  • String
  • Float
  • Bool
  • None

19 of 43

Variable Manipulation: Mathematical Operations

  • Addition
  • Subtraction
  • Division
  • Multiplication
  • Exponentiation

20 of 43

Variable Manipulation: String Operations

  • Concatenation (i.e join string)
  • Length of string

21 of 43

Collection Data Types

  • List
  • Tuple
  • Dictionary
  • Set

22 of 43

List Declaration:

Variable Declaration + Square Brackets

23 of 43

List Concatenation / Join (½)

24 of 43

List Concatenation / Join (2/2)

25 of 43

List Append

26 of 43

List Sorting (½)

[-122, -19, 23, 30, 53, 100, 100.05]

27 of 43

List Sorting (2/2)

28 of 43

Dictionary

  • Contains key-value pairs
  • Each key is mapped to a value
  • Data for each key can be retrieved from dictionary
  • Keys are unique in a specific instance of dictionary

29 of 43

Dictionary Declaration

30 of 43

Dictionary Retrieve Data Using Keys

31 of 43

Dictionary: Add key-value pair in existing dict

32 of 43

Functions

  • A function is a block of code which only runs when it is called.
  • You can pass data, known as parameters, into a function.
  • A function can return data as a result.

33 of 43

Simple Example of Function

34 of 43

Function (Contd.)

  • Functions ensure we can re-use the logic of a piece of code and able to functionize them
  • They are basically to enable automation

35 of 43

Quadratic Formula via Function

36 of 43

Boolean Operators

  • Any operator that computes a boolean value i.e. True or False
  • Usually they compare 2 (or more values)
  • For example, greater than, greater than or equal to, equal to

37 of 43

Equal To, Greater Than, Greater Than Equal To, etc.

38 of 43

Conditionals: If/Else

  • If/Else is the medium to execute different lines of code based on some logical condition
  • It is present in all programming languages in some form.

Remember, not ALL If/Else have ELSE block present.

39 of 43

If / Else Example: Odd or Even Number

40 of 43

For Loop

  • For loop is used when we need to same process (i.e. do operations) on a number of elements
  • It saves the programmer from writing same code multiple times

41 of 43

For Loop: Printing elements of a List

42 of 43

FizzBuzz Problem

  • Print the following for all numbers from 1 to 100:
    • If the number is divisible by 3, print ‘Fizz’
    • If the number is divisible by 5, print ‘Buzz’
    • If the number is NOT divisible by 3 or 5, then print the number itself

43 of 43

Feedback Survey Alert!

Thank you! :-)