[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Yashduttop/python-and-django-path/master/python/1.%20python.md [Back]  [Original]

# 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 ...

```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](https://www.python.org/dev/peps/pep-0008/)

### Tutorial

Python tutorial (official docs)

Go through the tutorial section of [python's official documentation](https://docs.python.org/3/tutorial/)

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](https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3) (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](https://www.youtube.com/watch?v=FsAPt_9Bf3U)

### Pip

Understanding the Python Package Manager.

- Learn what pip does
- Always do this inside your activated virtual environment
- pip freeze command. `pip freeze > requirements.txt`
- pip install command `pip install -r requirements.txt`

## 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. Ensure this code is generated by `pip freeze`
* 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.
1. Initialize python project with a separate virtualenv. All your code should be in Python.
1. Enable pylint for this project.
1. This project should have separate repo on Gitlab.com.
1. 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](https://www.youtube.com/playlist?list=PL2_aWCzGMAwI9HK8YPVBjElbLbI3ufctn) (30 minutes) on mycodeschool - 4 videos

[Complexity for recursive programs](https://www.youtube.com/watch?v=ncpTxqK35PI) (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.
1. Initialize a python project with a separate virtualenv. All your code should be in Python.
1. **Important**: flake8 should not throw any errors.
2. This project should have a separate repo on Gitlab.com.
3. 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.  10Cr

**Note:**
* The x-axis labels should be strings listed above, like "

Web Proxy Viewer  |  New URL  |  Original Page