FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

python-django-path/python/1. python.md at master · crazyvenky/python-django-path · GitHub

Latest commit

 

History

History
330 lines (206 loc) · 11.2 KB

File metadata and controls

330 lines (206 loc) · 11.2 KB

Python

1. Python Basics

Installation

Typically you don't need to do anything to get python. It should already, be installed on Ubuntu.

Just be sure, make sure you have python 3.7 or later installed on your system. Type in the following command in your shell ...

$ python3 --version

which should return something like

Python 3.8.2

Check your python installation

You should ...

  1. Have python 3.7+
  2. be able to install packages via pip
  3. Have virtualenv installed
  4. python plugin for VSCode installed
  5. setup pylint and enable pylint on VSCode

Get familiar with virtualenv. It is really important.

Understand PEP8

Go through PEP-8 Style Guide

Tutorial

Python tutorial (official docs)

Go through the tutorial section of python's official documentation

I want you to do all the material up to and including chapter 9. Optionally if you have time, do the other chapters also.

If you are new to python, the following is a good starting point.

Python Tutorial (Do only the first 68 videos).

Note: for those who already know python skim through the videos and mark this lesson as done.

Note: There are many, good, resources for python available on the internet. Feel free to use those resources. When you confidant of all the concepts present in this series, mark this section as done.

Python Decorators

Decorators

Data Project

Guidelines

Checklist

General guildelines for everyone:

  • Put all code in functions. E.g. - calculate, plot, execute (that calls calculate and plot). execute() can be called as the last line in the file.
  • Use DictReader instead of Reader. It makes the calculate function shorter.
  • Do most of the computation in the csv reading loop itself. - Don't have objects copying the entire dataset. This shoots up space complexity.
  • Variable names should be descriptive. Don't use single character names.
  • Instead of row in csv_reader. Use matches in matches_reader. Improves readability.
  • Instead of row[3], use constants with descriptive names. Example:
BATTING_TEAM_INDEX = 3

# In function

match[BATTING_TEAM_INDEX]
  • Create .gitignore entries for data-files, IDE files, temp files etc. Take Python Gitignore from here: https://github.com/github/gitignore/blob/main/Python.gitignore
  • Create README.md with just enough instruction install libs and run your code
  • Create requirements.txt for all the libraries used
  • Make sure it passes flake8 or pylint

Then submit your GitLab URL.

IPL data set analytics

Aim

To convert raw open data (run by run records in this case) into charts that tell some kind of story.

raw data

The data for this exercise is sourced from https://www.kaggle.com/manasgarg/ipl/version/5.

NOTE you might have to find data sources on your own. For example the country of origin for the Umpires.

Instructions

  1. Download all the data needed. Consult your mentor if you have any problems accessing the raw data.
  2. Initialize python project with a separate virtualenv. All your code should be in Python.
  3. Enable pylint for this project.
  4. This project should have separate repo on Gitlab.com.
  5. All projects should have README.md with instructions on how to run this project.

What your program should do

From the CSV and other source files specified above, write python code to ...

  1. Read in the data.
  2. Write logic to slice / dice / accumulate / transform the data.
  3. Using matplotlib plot the plots specified in the following section.

Problems

1. Total runs scored by team

Plot a chart of the total runs scored by each teams over the history of IPL. Hint: use the total_runs field.

2. Top batsman for Royal Challengers Bangalore

Consider only games played by Royal Challengers Bangalore. Now plot the total runs scored by top 10 batsman playing for Royal Challengers Bangalore over the history of IPL.

Plot only top 10 batsmen by runs scored in RCB.

3. Foreign umpire analysis

Obtain a source for country of origin of umpires. Plot a chart of number of umpires by in IPL by country. Indian umpires should be ignored as this would dominate the graph.

4. Stacked chart of matches played by team by season

Plot a stacked bar chart of ...

  • number of games played
  • by team
  • by season
5. Number of matches played per year for all the years in IPL.

Plot a bar chart.

6. Number of matches won per team per year in IPL.

Plot a stacked bar chart.

7. Extra runs conceded per team in the year 2016

Plot a bar chart.

8. Top 10 economical bowlers in the year 2015

Plot a bar chart.

Time Complexity

Time Complexity Summary (30 minutes) on mycodeschool - 4 videos

Complexity for recursive programs (8 minutes) on mycodeschool

Company Master - Maharashtra

Aim

To convert raw open data into plots, that tell a story on the state of company registration in Maharashtra.

raw data

Name source
Company master data of Maharashtra https://data.gov.in/catalog/company-master-data

Instructions

  1. Download all the data needed. Consult your mentor if you have any problems accessing the raw data.
  2. Initialize a python project with a separate virtualenv. All your code should be in Python.
  3. Important: flake8 should not throw any errors.
  4. This project should have a separate repo on Gitlab.com.
  5. All projects should have README.md with instructions on how to run this project.
What your program should do

From the CSV and other source files specified above, write python code to ...

  1. Read in the data.
  2. Write logic to slice / dice / accumulate / transform the data.
  3. Using matplotlib plot the plots specified in the following section.

Problems

1. Histogram of Authorized Cap

Plot a histogram on the "Authorized Capital" (column: AUTHORIZED_CAP) with the following intervals

  1. <= 1L
  2. 1L to 10L
  3. 10L to 1Cr
  4. 1Cr to 10Cr
  5. > 10Cr

Note:

  • The x-axis labels should be strings listed above, like "<= 1L".
  • You will have to adjust the intervals if you have an un-balanced plot.
2. Bar Plot of company registration by year

From the column, DATE_OF_REGISTRATION parse out the registration year. Using this data, plot a bar plot of the number of company registrations, vs. year.

3. Company registration in the year 2015 by the district.

The district can be found by zip code. This resource has that data. Before you start on this problem please make a CSV of zip code vs. district.

In this exercise ...

  1. Only consider registrations for the year 2015.
  2. Find out the district of registration by the zip code. The zip code can be found at the end of the address column.
  3. Count the registration by the district.
  4. Plot a "Bar plot" of "Number of Registration" vs. district.
  5. If the plot is unbalanced consider plotting only the top districts.
4. Grouped Bar Plot.

Plot a Grouped Bar Plot by aggregating registration counts over ...

  1. Year of registration
  2. Principal Business Activity

Plot only top 5 Prinicipal Business Activity for last 10 years

An example of a Grouped Bar Plot is here

Analytics on UN Population

Aim

To convert raw open data, country and year wise population estimates in this case, into charts that tell some kind of story.

raw data

The data for this exercise is sourced from https://datahub.io/core/population-growth-estimates-and-projections/r/population-estimates.csv

NOTE You have to construct data for countries in ASEAN and SAARC, references follow ...

Instructions

  1. Download all the data needed. Consult your mentor if you have any problems accessing the raw data.
  2. Initialize python project with a separate virtualenv. All your code should be in Python.
  3. Enable pylint for this project.
  4. This project should have separate repo on Gitlab.com.
  5. All projects should have README.md with instructions on how to run this project.

What your program should do

From the CSV and other source files specified above, write python code to ...

  1. Read in the data.
  2. Write logic to slice / dice / accumulate / transform the data.
  3. Using matplotlib plot the plots specified in the following section.

Plots

1: India population over years - Bar Plot

Make a Bar Plot of 'population of India' vs. years.

2: For the year 2014. Bar Chart of population of ASEAN countries

ASEAN is a collection of South East Asian countries. Plot a Bar Chat of the population of these countries. Only use data for the year 2014

3: Over the years, TOTAL population of SAARC countries

In this case for each year you have to calculate the sum of the population of all SAARC countries. Then plot a BAR CHART of Total SAARC population vs. year.

4: Grouped Bar Chart - ASEAN population vs. years

Grouped Bar Charts: https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/barchart.html

In grouped bar charts we can group together may related bar of a single value of the x-axis. You have to plot population of ASEAN countries as groups over the years 2004 - 2014.

Game Project

Get comfortable with Pygame. Go through online tutorials and build one.

After that, discuss with your mentor and pick up a game.

Write your own code. Create your own objects, functions and constants. The goal is to try and not make it perfect.

Use the same mechanics:

  • Game loop
  • Calculating the coordinates of objects
  • Rendering objects on screen
  • Showing score
  • Game end condition

Unit Testing

Get familiar with Unit Testing by watching some videos on Youtube.

Rewrite the data project. Create your own smaller dataset - like 5 matches and 15 deliveries. Manually set the result for the unit tests.

Code python functions that will transform the raw csv data into a data structure in a format suitable for plotting with matplotlib.

Only execute functions will be tested. Not the plot one.

Use unittest framework and coverage.py

Generate the following plots ...

  1. Plot the number of matches played per year of all the years in IPL.
  2. Plot a stacked bar chart of matches won of all teams over all the years of IPL.
  3. For the year 2016 plot the extra runs conceded per team.
  4. For the year 2015 plot the top economical bowlers.

Points to Consider while coding:

  • mock_matches.csv
  • mock_deliveries.csv
  • Using unittest framework
  • Using coverage for testing the coverage on execute function

Python Self Review

Write a technical paper on the following concepts.

  1. Array methods
  2. String methods
  3. Objects and Object Oriented Programming

Back | FazBrowse Home | New Git URL