Python Workshop
Python Workshop
Logan Halstrom
October 05, 2017
Outline
Installation
Sublime Text 3
Anaconda
Python Setup
Running Python
Ipython
Python Fundamentals
Loops
Loading Data and Plotting
Logical Operators
Functions
Dictionaries
Loading Data and Pandas
2. Click ‘Next’
List Subsets
Get subset of a list by entering a range of indices
Indexing syntax: [start:end+1]
Range from left index up to but not including right index
13 print(x[0:2]) #1st and 2nd values =[1,2] (subtract 1 from last index)
14 print(x[:-2]) #1st thru 3rd from last values =[1,2,3] (zero implied)
15 print(x[1:]) #2nd thru last values =[2,3,4,5] (last index implied)
Logan Halstrom
code from ‘lists.py’ October 05, 2017 22
Running Python Python Fundamentals
Lists
Assigning List Elements
Assign an index a new value using ‘=’
18 #List index assignment
19 x[1] = 10 #2nd item of x now 10 instead of 2 (x=[1,10,3,4,5])
Exercise: Plot data for 3 curves like ‘InClass Loops.py’ and then
rotate the curves like ‘makedata.py’ using dictionaries
1. Start a new script in Sublime Text
2. Save script ‘dictionary.py’ in desired location
3. Perform standard imports
4. Initialize dictionary with curly brackets
10 import numpy as np
11 import matplotlib.pyplot as plt
12
13 dat = {} #Dictionary to store all data sets
code from ‘dictionary.py’