Miki Tebeka 📬 miki@353solutions.com, 𝕏 @tebeka, 👨 mikitebeka, ✒️blog
- 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
- intro.py - Introduction to Python, looping, variables ...
- euler8.py - Project Euler #8
- text.py - Working with text,
str
andbytes
- looping.py - Looping utilities:
range
,enumerate
,zip
,reversed
- data_types.py - More data types:
list
,tuple
,dict
What is the most common word in data/road.txt
ignoring case?
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.
- How to Think Like a Computer Scientist: Interactive Edition
- The Python Tutorial
- pythontutor - Visualize Python execution
- itertools module
- Read and understand the "Itertools Recipes" section
- Iterators
- Iterators in the Python tutorial
- itertools - Iterator utilities (good reading ☺)
- Generator Tricks for System Programmers
- Generators: The Final Frontier
- Python Type Conversion
- List of Unicode Characters
- Project Euler
- Data Science Handbook
- Google Colab - Notebooks in the cloud
- http.log.gz
- road.txt
- ☺
- ♡
- List comprehensions
- Defining & calling functions
- Working with files
- Handling resources using
with
- Error handling
- Modules & packages (imports)
- Calling REST APIs
- equal.py - Identity vs equality
- funcs.py - Defining & calling functions
- github.py - Get user info from GitHub, JSON
- imports.py - Importing modules
- kill_server.py - Error handling
- list_comprehension.py - List comprehensions
- sync.py - Sync context of two directories
- word_freq.py - Word frequency
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
- Programming Exercises:
- HTTP in cats
- The Zen of Python (or
import this
) - Year 2038 problem
- List comprehension in the Python tutorial
- Defining functions in the Python tutorial
- pathlib module - Handling file paths
- shutil module - shell like utlities
- Context Managers and Python's "with" Statement
- Errors and Exceptions in the Python tutorial
- Modules in the Python tutorial
- JSON specification
- Python's json module
- A typical HTTP session
- http.log.gz
https://api.github.com/users/tebeka
- OO Basics
- Classes and instances
- Methods
- Special methods
- Inheritance
- Managing dependencies with pip
- Tesing with pytest
- Test cases
- Parametrized tests
- Fixtures
- num_http_errors.py - Count errors in
http.log.gz
- github.py - Get user info from GitHub, JSON
- game.py - OO
- class_utils.py - Class creation utilities (namedtuple, dataclass)
- nlp_test.py - Testing with PyTest
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
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 studentstudent_avg(student)
- return the average score for a studenttest_avg(test)
- return the average score for a test
Write tests for the class using pytest
.
- Classes in the Python tutorial
- Installing packages
- Using Python's pip to Manage Your Projects' Dependencies
- Other package managers
- pytest
- Linters
- colab notebook
- Beyond PEP8
- Pandas overview
- Loading data
- Selecting data
- Running calculations
- Grouping data
- Cleaning data
- Visualization
- taxi.py - Data processing with Pandas
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:
- DataFrame.apply
- [Series.shift](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.shift.html
- Pandas
- Visualization
- NYC Taxi
- Kaggle - Data science competitions
- VSCode Jupyter Extension
- Magic commands
- e.g.
%timeit 2 ** 1000
- e.g.
- PyCon Israel
- March 2020 Yellow Taxi Trip Records
- Data Dictionary - Yellow
!curl -LO https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2020-03.parquet
./.venv/bin/python -m pip install pyarrow
- NYC_Weather_2016_2022.csv.gz