Skip to content

353solutions/cybr-py-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Workshop @ CyberArk

Miki Tebeka 📬 miki@353solutions.com, 𝕏 @tebeka, 👨 mikitebeka, ✒️blog

Syllabus

Shameless Plugs


Day 1: Getting Started

Agenda

  • Intro to Python and its ecosystem
  • Working with the Python REPL
  • Working with text: str/bytes, formatting
  • Collections: list, tuple, dict & set
  • Slicing & List comprehensions
  • Control flow & logic
  • Iteration & iteration utilities

Code

  • intro.py - Introduction to Python, looping, variables ...
  • euler8.py - Project Euler #8
  • text.py - Working with text, str and bytes
  • looping.py - Looping utilities: range, enumerate, zip, reversed
  • data_types.py - More data types: list, tuple, dict

Exercises

Word Frequency

What is the most common word in data/road.txt ignoring case?

Stocks

Look at data/stocks.csv

You can read the content using the following code:

with open('data/stocks.csv') as fp:
    data = fp.read()

Answer the following questions:

  • Print sorted unique list of symbols (CSCO ...)
  • Print how many stocks of CSCO we own (symbol)
  • Print how much money we've invested (price * volume)

Using the data from data/prices.csv, print how much we've gained or lost.

Links

Data & Other


Day 2: Working with Python

Agenda

  • List comprehensions
  • Defining & calling functions
  • Working with files
  • Handling resources using with
  • Error handling
  • Modules & packages (imports)
  • Calling REST APIs

Code

Exercises

Count Errors

How many requests in http.log.gz resulted in an error (status code >= 400)? Use gzip.open to read the file.

Example lines:

uplherc.upl.com - - [01/Aug/1995:00:00:08 -0400] "GET /images/ksclogo-medium.gif HTTP/1.0" 304 0
uplherc.upl.com - - [01/Aug/1995:00:00:08 -0400] "GET /images/MOSAIC-logosmall.gif HTTP/1.0" 304 0
uplherc.upl.com - - [01/Aug/1995:00:00:08 -0400] "GET /images/USA-logosmall.gif HTTP/1.0" 304 0
ix-esc-ca2-07.ix.netcom.com - - [01/Aug/1995:00:00:09 -0400] "GET /images/launch-logo.gif HTTP/1.0" 200 1713
uplherc.upl.com - - [01/Aug/1995:00:00:10 -0400] "GET /images/WORLD-logosmall.gif HTTP/1.0" 304 0
slppp6.intermind.net - - [01/Aug/1995:00:00:10 -0400] "GET /history/skylab/skylab.html HTTP/1.0" 200 1687
piweba4y.prodigy.com - - [01/Aug/1995:00:00:10 -0400] "GET /images/launchmedium.gif HTTP/1.0" 200 11853
slppp6.intermind.net - - [01/Aug/1995:00:00:11 -0400] "GET /history/skylab/skylab-small.gif HTTP/1.0" 200 9202

Links

Data & Other


Day 3

Agenda

  • OO Basics
    • Classes and instances
    • Methods
    • Special methods
    • Inheritance
  • Managing dependencies with pip
  • Tesing with pytest
    • Test cases
    • Parametrized tests
    • Fixtures

Code

Exercises

Stock Tweets

Write a function related_stocks(symbol) that will return a list of stocks mentioned when you query this symbol on stocktweets.com.

To find about AAPL use https://api.stocktwits.com/api/2/streams/symbol/AAPL.json

A Tests Class

Write a Tests class that helps a teacher with student grades.

It should have the following methods:

  • add_score(student, test, score) - add a score for a student
  • student_avg(student) - return the average score for a student
  • test_avg(test) - return the average score for a test

Write tests for the class using pytest.

Links

Data & Other


Day 4: Data Processing with Pandas

  • Pandas overview
  • Loading data
  • Selecting data
  • Running calculations
  • Grouping data
  • Cleaning data
  • Visualization

Code

  • taxi.py - Data processing with Pandas

Exercise

Load track.csv and draw a box plot of Miki's running speed in km/h. To calculate the distance between two coordinates, use the following code:

import numpy as np


lat_km = 92
lng_km = 111


def distance(lat1, lng1, lat2, lng2):
    """Return euclidean distance (in kilometers) between two coordinates

    >>> distance(0, 0, 1, 1)
    144.1700384962146
    """
    delta_lat = (lat1 - lat2) * lat_km
    delta_lng = (lng1 - lng2) * lng_km
    return np.hypot(delta_lat, delta_lng)

Hints:

Links

Data & Other

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published