├── Day 2 ├── 2. Pandas │ ├── Book1.csv │ ├── cars.csv │ ├── BRICS.csv │ ├── 3. Example_cars.ipynb │ ├── .ipynb_checkpoints │ │ ├── Example_cars-checkpoint.ipynb │ │ ├── Example_BRICS-checkpoint.ipynb │ │ └── pandas-checkpoint.ipynb │ ├── iris.csv │ ├── 2. Example_BRICS.ipynb │ └── 1. pandas.ipynb ├── 4. Classifiers │ ├── Classification models.txt │ ├── classify.py │ ├── ScrappyNN.py │ ├── 1. Simple Hello World.ipynb │ ├── .ipynb_checkpoints │ │ ├── Simple Hello World-checkpoint.ipynb │ │ └── Classifier_IRIS-checkpoint.ipynb │ ├── iris.csv │ └── 2. Classifier_IRIS.ipynb ├── 3. Data Visualization Matplotlib │ ├── 3. Histograms.ipynb │ ├── .ipynb_checkpoints │ │ ├── Histograms-checkpoint.ipynb │ │ ├── SimplePlots-checkpoint.ipynb │ │ └── Customisations-checkpoint.ipynb │ ├── world_pop.csv │ ├── 1. SimplePlots.ipynb │ ├── raw_data_to_csv.py │ ├── 2. Customisations.ipynb │ ├── example.csv │ └── Raw Data.txt └── 1. NumPy Revision Tour │ └── Untitled.ipynb ├── MLCC Day 1.pdf ├── MLCC Day 2.pdf ├── Day 3 ├── Day 3.pptx ├── scrappy_KNN.py └── digit_classify.py ├── Day 1 ├── 4. Numpy and Pandas │ ├── Book1.csv │ └── iris.csv ├── 2. Strings Standard Input and Files │ ├── myfile.txt │ ├── 1. Stdin.ipynb │ ├── .ipynb_checkpoints │ │ ├── Stdin-checkpoint.ipynb │ │ ├── Files-checkpoint.ipynb │ │ └── Strings-checkpoint.ipynb │ ├── 3. Files.ipynb │ └── 2. Strings.ipynb ├── 5. Machine Learning Hello World │ ├── .ipynb_checkpoints │ │ └── MNIST_Classifier-checkpoint.ipynb │ ├── IrisClassifier.py │ ├── DigitClassifier.py │ └── iris.csv ├── 1. Basic Programming Constructs │ ├── 3. Conditionals.ipynb │ ├── .ipynb_checkpoints │ │ ├── Conditionals-checkpoint.ipynb │ │ ├── Iteration-checkpoint.ipynb │ │ ├── Variables-checkpoint.ipynb │ │ └── Functions-checkpoint.ipynb │ ├── 4. Iteration.ipynb │ ├── 1. Variables.ipynb │ └── 5. Functions.ipynb └── 3. List Tuples and Dictionaries │ ├── 4. List_comprehensions.ipynb │ ├── .ipynb_checkpoints │ ├── List_comprehensions-checkpoint.ipynb │ └── Tuples-checkpoint.ipynb │ └── 3. Tuples.ipynb └── README.md /Day 2/2. Pandas/Book1.csv: -------------------------------------------------------------------------------- 1 | Revenue,profit 2 | 3000,6000 3 | 4000,10000 4 | 5000,15000 5 | -------------------------------------------------------------------------------- /MLCC Day 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naveen21553/ml-workshop/HEAD/MLCC Day 1.pdf -------------------------------------------------------------------------------- /MLCC Day 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naveen21553/ml-workshop/HEAD/MLCC Day 2.pdf -------------------------------------------------------------------------------- /Day 3/Day 3.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naveen21553/ml-workshop/HEAD/Day 3/Day 3.pptx -------------------------------------------------------------------------------- /Day 1/4. Numpy and Pandas/Book1.csv: -------------------------------------------------------------------------------- 1 | Revenue,profit 2 | 3000,6000 3 | 4000,10000 4 | 5000,15000 5 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/myfile.txt: -------------------------------------------------------------------------------- 1 | Hello World 2 | Simple is better than complex 3 | Complex is better than complicated -------------------------------------------------------------------------------- /Day 1/5. Machine Learning Hello World/.ipynb_checkpoints/MNIST_Classifier-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/cars.csv: -------------------------------------------------------------------------------- 1 | Code,Cars_Per_Cap,Country,drives_right 2 | US,809,United States,True 3 | AUS,731,Australia,False 4 | JAP,588,Japan,False 5 | IN,18,India,False 6 | RU,200,Russia,True 7 | MOR,70,Morocco,True 8 | EG,45,Egypt,True -------------------------------------------------------------------------------- /Day 2/2. Pandas/BRICS.csv: -------------------------------------------------------------------------------- 1 | ,country,capital,area,population 2 | BR,Brazil,Brasilia,8.516,200.40 3 | RU,Russia,Moscow,17.100,143.50 4 | IN,India,New Delhi,3.286,1252.00 5 | CH,China,Beijing,9.597,1357.00 6 | SA,South Africa,Pretorica,1.221,52.98 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ml-workshop 2 | Machine Learning Workshop Files 3 | 4 | If you like the content, please star this repository 5 | If you feel there is something wrong, feel free to give a pull request 6 | 7 | The workshop is split in multiple days, 8 | Each day has files classified into categories 9 | 10 | to download these files, type in git-bash 11 | 12 | git clone https://github.com/naveen21553/ml-workshop/ 13 | 14 | or click on download and download as zip 15 | 16 | 17 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/Classification models.txt: -------------------------------------------------------------------------------- 1 | -- Datasets 2 | from sklearn.datasets import load_digits 3 | 4 | -- train_test_split() 5 | from sklerarn.cross_validation import train_test_split 6 | from sklearn.model_selection import train_test_split 7 | 8 | -- classification models 9 | from sklearn.linear_model import LogisticRegression 10 | from sklearn.tree import DecisionTreeClassifier 11 | from sklearn.neighbors import KNeighborsClassifier 12 | 13 | -- metrices 14 | from sklearn.metrics import confusion_matrix 15 | from sklearn.metrics import accuracy_score 16 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/classify.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | features_df = pd.read_csv('iris.csv', usecols = [0,1,2,3], skiprows = 1, names = ['Sepal_Len', 'Sepal_Wid', 'Petal_Len', 'Petal_Wid']) 4 | labels_df = pd.read_csv('iris.csv', usecols = [4], skiprows = 1, names = ['Labels']) 5 | 6 | features = features_df.values 7 | labels = labels_df.values.ravel() 8 | 9 | from sklearn.model_selection import train_test_split 10 | 11 | x_train, x_test, y_train, y_test = train_test_split(features, labels, test_size = 0.23, random_state = 2) 12 | 13 | from sklearn.linear_model import LogisticRegression 14 | 15 | logReg = LogisticRegression() 16 | logReg.fit(x_train, y_train) 17 | 18 | print(logReg.predict(x_test[0].reshape(1, -1))) 19 | print(y_test[0]) 20 | 21 | predictions = logReg.predict(x_test) 22 | 23 | score = logReg.score(x_test, y_test) 24 | 25 | print(score) 26 | 27 | from sklearn.metrics import confusion_matrix 28 | 29 | cm = confusion_matrix(y_test, predictions) 30 | print(cm) -------------------------------------------------------------------------------- /Day 1/5. Machine Learning Hello World/IrisClassifier.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from sklearn import metrics 3 | import numpy as np 4 | from sklearn.model_selection import train_test_split 5 | from sklearn.linear_model import LogisticRegression 6 | irisdata = pd.read_csv('iris.csv', skiprows = 1, usecols=[0,1,2,3], names = ['Sepal_len', 'Sepal_wid', 'Petal_len', 'Petal_wid']) 7 | 8 | labels_df = pd.read_csv('iris.csv', header = None, skiprows=1, usecols=[4], names=['labels']) 9 | 10 | features = irisdata.values 11 | labels = labels_df.values.ravel() 12 | 13 | x_train, x_test, y_train, y_test = train_test_split(features, labels, test_size = 0.25, random_state = 2) 14 | 15 | logReg = LogisticRegression() 16 | 17 | print(x_train.shape) 18 | print(y_train.shape) 19 | #print(x_train) 20 | #print(y_train) 21 | 22 | logReg.fit(x_train, y_train) 23 | predictions = logReg.predict(x_test) 24 | 25 | score = logReg.score(x_test, y_test) 26 | cm = metrics.confusion_matrix(y_test, predictions) 27 | print(cm) 28 | print('predicted\tactual') 29 | for predicted, actual in zip(predictions, y_test): 30 | print(predicted, actual, sep='\t') -------------------------------------------------------------------------------- /Day 1/5. Machine Learning Hello World/DigitClassifier.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | from sklearn.linear_model import LogisticRegression 4 | from sklearn.model_selection import train_test_split 5 | from sklearn.datasets import load_digits 6 | from sklearn import metrics 7 | 8 | digits = load_digits() 9 | print('data: ', digits.data.shape) 10 | print('labels: ', digits.target.shape) 11 | print(type(digits)) 12 | 13 | plt.figure(figsize=(20,4)) 14 | ''' 15 | for index, (image, label) in enumerate(zip(digits.data[0:5], digits.target[0:5])): 16 | plt.subplot(1, 5, index + 1) 17 | plt.imshow(np.reshape(image, (8,8)), cmap = plt.cm.gray) 18 | plt.title('Training: %i\n' %label, fontsize = 20) 19 | plt.show() 20 | ''' 21 | 22 | x_train, x_test, y_train, y_test = train_test_split(digits.data, digits.target, test_size=0.23, random_state = 2) 23 | 24 | print(x_train.shape) 25 | print(y_train.shape) 26 | 27 | logReg = LogisticRegression() 28 | 29 | logReg.fit(x_train, y_train) 30 | 31 | ''' 32 | plt.figure(figsize=(4,4)) 33 | plt.imshow(np.reshape(x_test[0], (8,8)), cmap = plt.cm.gray) 34 | ''' 35 | print(y_test[0]) 36 | print(logReg.predict(x_test[0].reshape(1,-1))) 37 | 38 | predictions = logReg.predict(x_test) 39 | score = logReg.score(x_test, y_test) 40 | print('score: ', score) 41 | 42 | cm = metrics.confusion_matrix(y_test, predictions) 43 | 44 | print('confusion matrix \n',cm) -------------------------------------------------------------------------------- /Day 2/4. Classifiers/ScrappyNN.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import load_iris 2 | from sklearn.model_selection import train_test_split 3 | #from sklerarn.cross_validation import train_test_split 4 | from sklearn.metrics import accuracy_score 5 | from sklearn.metrics import confusion_matrix 6 | import random 7 | from scipy.spatial.distance import euclidean 8 | 9 | class ScrappyNN(): 10 | def fit(self, x_train, y_train): 11 | self.X_train = x_train 12 | self.Y_train = y_train 13 | 14 | def predict(self, x_test): 15 | predictions = [] 16 | for i in x_test: 17 | label = self.closest(i) 18 | predictions.append(label) 19 | 20 | return predictions 21 | 22 | def closest(self, i): 23 | best_dist = euclidean(i, self.X_train[0]) 24 | best_index = 0 25 | 26 | for j in range(1, len(self.X_train)): 27 | dist = euclidean(i, self.X_train[j]) 28 | if dist < best_dist: 29 | best_dist = dist 30 | best_index = j 31 | 32 | return self.Y_train[best_index] 33 | 34 | iris = load_iris() 35 | print(iris.feature_names, iris.target_names, sep='\n') 36 | 37 | x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size = 0.30, random_state = 3) 38 | 39 | clf = ScrappyNN() 40 | clf.fit(x_train, y_train) 41 | predictions = clf.predict(x_test) 42 | 43 | score = accuracy_score(predictions, y_test) 44 | 45 | print(score) 46 | 47 | cm = confusion_matrix(y_test, predictions) 48 | 49 | print(cm) 50 | 51 | -------------------------------------------------------------------------------- /Day 3/scrappy_KNN.py: -------------------------------------------------------------------------------- 1 | import random 2 | from scipy.spatial.distance import euclidean as dist 3 | 4 | class myKNN(): 5 | def fit(self, x_train, y_train): 6 | self.X_train = x_train 7 | self.Y_train = y_train 8 | 9 | def predict(self, x_test): 10 | predictions = [] 11 | for item in x_test: 12 | prediction = self.closest(item) 13 | predictions.append(prediction) 14 | return predictions 15 | 16 | def closest(self, item): 17 | best_dist = dist(self.X_train[0], item) 18 | best_index = 0 19 | 20 | for i in range(1, len(self.X_train)): 21 | distance = dist(self.X_train[i], item) 22 | if distance < best_dist: 23 | best_dist = distance 24 | best_index = i 25 | return self.Y_train[best_index] 26 | 27 | from sklearn.datasets import load_iris 28 | from sklearn.model_selection import train_test_split 29 | 30 | iris = load_iris() 31 | x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size = 0.23) 32 | 33 | #from sklearn.neighbors import KNeighborsClassifier 34 | clf = myKNN() 35 | 36 | clf.fit(x_train, y_train) 37 | predictions = clf.predict(x_test) 38 | 39 | from sklearn.metrics import accuracy_score 40 | score = accuracy_score(predictions, y_test) 41 | 42 | from sklearn.metrics import confusion_matrix 43 | cm = confusion_matrix(predictions, y_test) 44 | 45 | print('Score: ', score) 46 | print(cm) -------------------------------------------------------------------------------- /Day 3/digit_classify.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import load_digits 2 | from sklearn.model_selection import train_test_split 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | import seaborn as sns 6 | 7 | digits = load_digits() 8 | print(digits.data.shape) 9 | print(digits.target.shape) 10 | 11 | plt.figure(figsize = (20,4)) 12 | for index, (image, label) in enumerate(zip(digits.data[:5], digits.target[:5])): 13 | plt.subplot(1, 5, index+1) 14 | plt.imshow(np.reshape(image, (8,8)), cmap=plt.cm.gray) 15 | plt.title('Training: %i\n'%label, fontsize=20) 16 | 17 | plt.show() 18 | 19 | x_train, x_test, y_train, y_test = train_test_split(digits.data, digits.target, test_size = 0.25, random_state = 2) 20 | 21 | from sklearn.neighbors import KNeighborsClassifier 22 | 23 | logreg = KNeighborsClassifier() 24 | logreg.fit(x_train, y_train) 25 | 26 | print(logreg.predict(x_test[0:10])) 27 | 28 | predictions = logreg.predict(x_test) 29 | 30 | score = logreg.score(x_test, y_test) 31 | from sklearn.metrics import accuracy_score 32 | score1 = accuracy_score(predictions, y_test) 33 | print('score: ', score) 34 | print('score1: ', score1) 35 | 36 | 37 | #Confusion Matric representation 38 | 39 | from sklearn.metrics import confusion_matrix 40 | cm = confusion_matrix(y_test, predictions) 41 | 42 | plt.figure(figsize=(9, 9)) 43 | sns.heatmap(cm, annot = True, fmt='.3f', linewidth=0.5, square=True, cmap='Blues_r') 44 | 45 | plt.ylabel('Actual label') 46 | plt.xlabel('Predicted label') 47 | 48 | title = 'Accuracy Score: {0}'.format(score) 49 | 50 | plt.title(title, size = 15) 51 | plt.show() -------------------------------------------------------------------------------- /Day 2/2. Pandas/3. Example_cars.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Working through pandas" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import pandas as pd" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "cars = pd.read_csv('cars.csv')" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "cars" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "cars = pd.read_csv('cars.csv', index_col = 0)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "cars" 53 | ] 54 | } 55 | ], 56 | "metadata": { 57 | "kernelspec": { 58 | "display_name": "Python 3", 59 | "language": "python", 60 | "name": "python3" 61 | }, 62 | "language_info": { 63 | "codemirror_mode": { 64 | "name": "ipython", 65 | "version": 3 66 | }, 67 | "file_extension": ".py", 68 | "mimetype": "text/x-python", 69 | "name": "python", 70 | "nbconvert_exporter": "python", 71 | "pygments_lexer": "ipython3", 72 | "version": "3.6.4" 73 | } 74 | }, 75 | "nbformat": 4, 76 | "nbformat_minor": 2 77 | } 78 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/.ipynb_checkpoints/Example_cars-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Working through pandas" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import pandas as pd" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "cars = pd.read_csv('cars.csv')" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "cars" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "cars = pd.read_csv('cars.csv', index_col = 0)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "cars" 53 | ] 54 | } 55 | ], 56 | "metadata": { 57 | "kernelspec": { 58 | "display_name": "Python 3", 59 | "language": "python", 60 | "name": "python3" 61 | }, 62 | "language_info": { 63 | "codemirror_mode": { 64 | "name": "ipython", 65 | "version": 3 66 | }, 67 | "file_extension": ".py", 68 | "mimetype": "text/x-python", 69 | "name": "python", 70 | "nbconvert_exporter": "python", 71 | "pygments_lexer": "ipython3", 72 | "version": "3.6.4" 73 | } 74 | }, 75 | "nbformat": 4, 76 | "nbformat_minor": 2 77 | } 78 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/3. Histograms.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Histograms in Matplotlib" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import matplotlib.pyplot as plt" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "x = [0.1, 2.3, 2.4, 3.4, 1.3, 5.6, 3.4, 2.5]" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "plt.hist(x, bins = 3)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a particular distribution. Which plot do you use?" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?" 49 | ] 50 | } 51 | ], 52 | "metadata": { 53 | "kernelspec": { 54 | "display_name": "Python 3", 55 | "language": "python", 56 | "name": "python3" 57 | }, 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.6.4" 69 | } 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 2 73 | } 74 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/.ipynb_checkpoints/Histograms-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Histograms in Matplotlib" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import matplotlib.pyplot as plt" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "x = [0.1, 2.3, 2.4, 3.4, 1.3, 5.6, 3.4, 2.5]" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "plt.hist(x, bins = 3)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a particular distribution. Which plot do you use?" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?" 49 | ] 50 | } 51 | ], 52 | "metadata": { 53 | "kernelspec": { 54 | "display_name": "Python 3", 55 | "language": "python", 56 | "name": "python3" 57 | }, 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.6.4" 69 | } 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 2 73 | } 74 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/world_pop.csv: -------------------------------------------------------------------------------- 1 | ,col1,col2 2 | 0,1950,2.53 3 | 1,1951,2.57 4 | 2,1952,2.62 5 | 3,1953,2.67 6 | 4,1954,2.71 7 | 5,1955,2.76 8 | 6,1956,2.81 9 | 7,1957,2.86 10 | 8,1958,2.92 11 | 9,1959,2.97 12 | 10,1960,3.03 13 | 11,1961,3.08 14 | 12,1962,3.14 15 | 13,1963,3.2 16 | 14,1964,3.26 17 | 15,1965,3.33 18 | 16,1966,3.4 19 | 17,1967,3.47 20 | 18,1968,3.54 21 | 19,1969,3.62 22 | 20,1970,3.69 23 | 21,1971,3.77 24 | 22,1972,3.84 25 | 23,1973,3.92 26 | 24,1974,4.0 27 | 25,1975,4.07 28 | 26,1976,4.15 29 | 27,1977,4.22 30 | 28,1978,4.3 31 | 29,1979,4.37 32 | 30,1980,4.45 33 | 31,1981,4.53 34 | 32,1982,4.61 35 | 33,1983,4.69 36 | 34,1984,4.78 37 | 35,1985,4.86 38 | 36,1986,4.95 39 | 37,1987,5.05 40 | 38,1988,5.14 41 | 39,1989,5.23 42 | 40,1990,5.32 43 | 41,1991,5.41 44 | 42,1992,5.49 45 | 43,1993,5.58 46 | 44,1994,5.66 47 | 45,1995,5.74 48 | 46,1996,5.82 49 | 47,1997,5.9 50 | 48,1998,5.98 51 | 49,1999,6.05 52 | 50,2000,6.13 53 | 51,2001,6.2 54 | 52,2002,6.28 55 | 53,2003,6.36 56 | 54,2004,6.44 57 | 55,2005,6.51 58 | 56,2006,6.59 59 | 57,2007,6.67 60 | 58,2008,6.75 61 | 59,2009,6.83 62 | 60,2010,6.92 63 | 61,2011,7.0 64 | 62,2012,7.08 65 | 63,2013,7.16 66 | 64,2014,7.24 67 | 65,2015,7.32 68 | 66,2016,7.4 69 | 67,2017,7.48 70 | 68,2018,7.56 71 | 69,2019,7.64 72 | 70,2020,7.72 73 | 71,2021,7.79 74 | 72,2022,7.87 75 | 73,2023,7.94 76 | 74,2024,8.01 77 | 75,2025,8.08 78 | 76,2026,8.15 79 | 77,2027,8.22 80 | 78,2028,8.29 81 | 79,2029,8.36 82 | 80,2030,8.42 83 | 81,2031,8.49 84 | 82,2032,8.56 85 | 83,2033,8.62 86 | 84,2034,8.68 87 | 85,2035,8.74 88 | 86,2036,8.8 89 | 87,2037,8.86 90 | 88,2038,8.92 91 | 89,2039,8.98 92 | 90,2040,9.04 93 | 91,2041,9.09 94 | 92,2042,9.15 95 | 93,2043,9.2 96 | 94,2044,9.26 97 | 95,2045,9.31 98 | 96,2046,9.36 99 | 97,2047,9.41 100 | 98,2048,9.46 101 | 99,2049,9.5 102 | 100,2050,9.55 103 | 101,2051,9.6 104 | 102,2052,9.64 105 | 103,2053,9.68 106 | 104,2054,9.73 107 | 105,2055,9.77 108 | 106,2056,9.81 109 | 107,2057,9.85 110 | 108,2058,9.88 111 | 109,2059,9.92 112 | 110,2060,9.96 113 | 111,2061,9.99 114 | 112,2062,10.03 115 | 113,2063,10.06 116 | 114,2064,10.09 117 | 115,2065,10.13 118 | 116,2066,10.16 119 | 117,2067,10.19 120 | 118,2068,10.22 121 | 119,2069,10.25 122 | 120,2070,10.28 123 | 121,2071,10.31 124 | 122,2072,10.33 125 | 123,2073,10.36 126 | 124,2074,10.38 127 | 125,2075,10.41 128 | 126,2076,10.43 129 | 127,2077,10.46 130 | 128,2078,10.48 131 | 129,2079,10.5 132 | 130,2080,10.52 133 | 131,2081,10.55 134 | 132,2082,10.57 135 | 133,2083,10.59 136 | 134,2084,10.61 137 | 135,2085,10.63 138 | 136,2086,10.65 139 | 137,2087,10.66 140 | 138,2088,10.68 141 | 139,2089,10.7 142 | 140,2090,10.72 143 | 141,2091,10.73 144 | 142,2092,10.75 145 | 143,2093,10.77 146 | 144,2094,10.78 147 | 145,2095,10.79 148 | 146,2096,10.81 149 | 147,2097,10.82 150 | 148,2098,10.83 151 | 149,2099,10.84 152 | 150,2100,10.85 153 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/1. Simple Hello World.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Machine Learning in 6 lines\n", 8 | "\n", 9 | "### Credits - Josh Gordon \n", 10 | "Google Developers\n", 11 | "\n", 12 | "https://www.youtube.com/watch?v=cKxRvEZd3Mw&list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "In features - \n", 20 | "- '0' - Bumpy\n", 21 | "- '1' - Clean\n", 22 | "\n", 23 | "In Labels - \n", 24 | "- '0' - Apple\n", 25 | "- '1' - Orange" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "features = [[140, 1], [130, 1], [150, 0], [170, 0]]\n", 35 | "labels = [0, 0, 1, 1]" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "#### Import Decision tree classifier" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "from sklearn.tree import DecisionTreeClassifier" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "#### Creating an instance of DecisionTreeClassifier Class" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "clf = DecisionTreeClassifier()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "#### Train our model" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "clf.fit(features, labels)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "#### testing the model" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "print(clf.predict([[135, 0]]))" 100 | ] 101 | } 102 | ], 103 | "metadata": { 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.6.4" 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 2 124 | } 125 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/.ipynb_checkpoints/Simple Hello World-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Machine Learning in 6 lines\n", 8 | "\n", 9 | "### Credits - Josh Gordon \n", 10 | "Google Developers\n", 11 | "\n", 12 | "https://www.youtube.com/watch?v=cKxRvEZd3Mw&list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "In features - \n", 20 | "- '0' - Bumpy\n", 21 | "- '1' - Clean\n", 22 | "\n", 23 | "In Labels - \n", 24 | "- '0' - Apple\n", 25 | "- '1' - Orange" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "features = [[140, 1], [130, 1], [150, 0], [170, 0]]\n", 35 | "labels = [0, 0, 1, 1]" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "#### Import Decision tree classifier" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "from sklearn.tree import DecisionTreeClassifier" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "#### Creating an instance of DecisionTreeClassifier Class" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "clf = DecisionTreeClassifier()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "#### Train our model" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "clf.fit(features, labels)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "#### testing the model" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "print(clf.predict([[135, 0]]))" 100 | ] 101 | } 102 | ], 103 | "metadata": { 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.6.4" 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 2 124 | } 125 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/3. Conditionals.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Conditionals in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## If Statement" 15 | ] 16 | }, 17 | { 18 | "cell_type": "raw", 19 | "metadata": {}, 20 | "source": [ 21 | "In python the syntax for if statement is - \n", 22 | "\n", 23 | "if expression:\n", 24 | " statements under if block\n", 25 | "statement outside if block" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 1, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "x is equal to 5\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "x = 5\n", 43 | "if x == 5:\n", 44 | " print('x is equal to 5')\n", 45 | "else:\n", 46 | " print('x is not 5')" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "if - elif - else" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "x is 2\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "x = 2\n", 71 | "\n", 72 | "if x == 1:\n", 73 | " print('x is 1')\n", 74 | " \n", 75 | "elif x == 2:\n", 76 | " print('x is 2')\n", 77 | " \n", 78 | "elif x == 3:\n", 79 | " print('x is 3')\n", 80 | " \n", 81 | "else:\n", 82 | " print('x is not 1 nor 2 nor 3')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "nested if - else" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 3, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "x is not between 1 and 5\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "x = 5\n", 107 | "if x > 1:\n", 108 | " if x < 5:\n", 109 | " print('x is between 1 and 5')\n", 110 | " else:\n", 111 | " print('x is not between 1 and 5')" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [] 120 | } 121 | ], 122 | "metadata": { 123 | "kernelspec": { 124 | "display_name": "Python 3", 125 | "language": "python", 126 | "name": "python3" 127 | }, 128 | "language_info": { 129 | "codemirror_mode": { 130 | "name": "ipython", 131 | "version": 3 132 | }, 133 | "file_extension": ".py", 134 | "mimetype": "text/x-python", 135 | "name": "python", 136 | "nbconvert_exporter": "python", 137 | "pygments_lexer": "ipython3", 138 | "version": "3.6.4" 139 | } 140 | }, 141 | "nbformat": 4, 142 | "nbformat_minor": 2 143 | } 144 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/.ipynb_checkpoints/Conditionals-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Conditionals in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## If Statement" 15 | ] 16 | }, 17 | { 18 | "cell_type": "raw", 19 | "metadata": {}, 20 | "source": [ 21 | "In python the syntax for if statement is - \n", 22 | "\n", 23 | "if expression:\n", 24 | " statements under if block\n", 25 | "statement outside if block" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 1, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "x is equal to 5\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "x = 5\n", 43 | "if x == 5:\n", 44 | " print('x is equal to 5')\n", 45 | "else:\n", 46 | " print('x is not 5')" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "if - elif - else" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "x is 2\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "x = 2\n", 71 | "\n", 72 | "if x == 1:\n", 73 | " print('x is 1')\n", 74 | " \n", 75 | "elif x == 2:\n", 76 | " print('x is 2')\n", 77 | " \n", 78 | "elif x == 3:\n", 79 | " print('x is 3')\n", 80 | " \n", 81 | "else:\n", 82 | " print('x is not 1 nor 2 nor 3')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "nested if - else" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 3, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "x is not between 1 and 5\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "x = 5\n", 107 | "if x > 1:\n", 108 | " if x < 5:\n", 109 | " print('x is between 1 and 5')\n", 110 | " else:\n", 111 | " print('x is not between 1 and 5')" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [] 120 | } 121 | ], 122 | "metadata": { 123 | "kernelspec": { 124 | "display_name": "Python 3", 125 | "language": "python", 126 | "name": "python3" 127 | }, 128 | "language_info": { 129 | "codemirror_mode": { 130 | "name": "ipython", 131 | "version": 3 132 | }, 133 | "file_extension": ".py", 134 | "mimetype": "text/x-python", 135 | "name": "python", 136 | "nbconvert_exporter": "python", 137 | "pygments_lexer": "ipython3", 138 | "version": "3.6.4" 139 | } 140 | }, 141 | "nbformat": 4, 142 | "nbformat_minor": 2 143 | } 144 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/1. SimplePlots.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Matplotlib - pyplot" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#### Import Library" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import matplotlib.pyplot as plt" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "year = [1950, 1970, 1990, 2010]\n", 33 | "pop = [2.159, 3.692, 5.263, 6.972]" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": { 40 | "scrolled": true 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "plt.plot(x,y)\n", 45 | "plt.show()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Scatter Plot" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": { 59 | "scrolled": true 60 | }, 61 | "outputs": [], 62 | "source": [ 63 | "plt.scatter(x, y)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "### adding more realistic data" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "import pandas as pd" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "df = pd.read_csv('world_pop.csv', skiprows = 1, usecols = [1, 2], names = ['year', 'pop'])" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "df.head()" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "df.columns" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "plt.plot(df['year'], df['pop'])" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "plt.scatter(df['year'], df['pop'])" 125 | ] 126 | } 127 | ], 128 | "metadata": { 129 | "kernelspec": { 130 | "display_name": "Python 3", 131 | "language": "python", 132 | "name": "python3" 133 | }, 134 | "language_info": { 135 | "codemirror_mode": { 136 | "name": "ipython", 137 | "version": 3 138 | }, 139 | "file_extension": ".py", 140 | "mimetype": "text/x-python", 141 | "name": "python", 142 | "nbconvert_exporter": "python", 143 | "pygments_lexer": "ipython3", 144 | "version": "3.6.4" 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 2 149 | } 150 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/.ipynb_checkpoints/SimplePlots-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Matplotlib - pyplot" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#### Import Library" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import matplotlib.pyplot as plt" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "year = [1950, 1970, 1990, 2010]\n", 33 | "pop = [2.159, 3.692, 5.263, 6.972]" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": { 40 | "scrolled": true 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "plt.plot(x,y)\n", 45 | "plt.show()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Scatter Plot" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": { 59 | "scrolled": true 60 | }, 61 | "outputs": [], 62 | "source": [ 63 | "plt.scatter(x, y)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "### adding more realistic data" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "import pandas as pd" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "df = pd.read_csv('world_pop.csv', skiprows = 1, usecols = [1, 2], names = ['year', 'pop'])" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "df.head()" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "df.columns" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "plt.plot(df['year'], df['pop'])" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "plt.scatter(df['year'], df['pop'])" 125 | ] 126 | } 127 | ], 128 | "metadata": { 129 | "kernelspec": { 130 | "display_name": "Python 3", 131 | "language": "python", 132 | "name": "python3" 133 | }, 134 | "language_info": { 135 | "codemirror_mode": { 136 | "name": "ipython", 137 | "version": 3 138 | }, 139 | "file_extension": ".py", 140 | "mimetype": "text/x-python", 141 | "name": "python", 142 | "nbconvert_exporter": "python", 143 | "pygments_lexer": "ipython3", 144 | "version": "3.6.4" 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 2 149 | } 150 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/iris.csv: -------------------------------------------------------------------------------- 1 | 150,4,setosa,versicolor,virginica 2 | 5.1,3.5,1.4,0.2,0 3 | 4.9,3.0,1.4,0.2,0 4 | 4.7,3.2,1.3,0.2,0 5 | 4.6,3.1,1.5,0.2,0 6 | 5.0,3.6,1.4,0.2,0 7 | 5.4,3.9,1.7,0.4,0 8 | 4.6,3.4,1.4,0.3,0 9 | 5.0,3.4,1.5,0.2,0 10 | 4.4,2.9,1.4,0.2,0 11 | 4.9,3.1,1.5,0.1,0 12 | 5.4,3.7,1.5,0.2,0 13 | 4.8,3.4,1.6,0.2,0 14 | 4.8,3.0,1.4,0.1,0 15 | 4.3,3.0,1.1,0.1,0 16 | 5.8,4.0,1.2,0.2,0 17 | 5.7,4.4,1.5,0.4,0 18 | 5.4,3.9,1.3,0.4,0 19 | 5.1,3.5,1.4,0.3,0 20 | 5.7,3.8,1.7,0.3,0 21 | 5.1,3.8,1.5,0.3,0 22 | 5.4,3.4,1.7,0.2,0 23 | 5.1,3.7,1.5,0.4,0 24 | 4.6,3.6,1.0,0.2,0 25 | 5.1,3.3,1.7,0.5,0 26 | 4.8,3.4,1.9,0.2,0 27 | 5.0,3.0,1.6,0.2,0 28 | 5.0,3.4,1.6,0.4,0 29 | 5.2,3.5,1.5,0.2,0 30 | 5.2,3.4,1.4,0.2,0 31 | 4.7,3.2,1.6,0.2,0 32 | 4.8,3.1,1.6,0.2,0 33 | 5.4,3.4,1.5,0.4,0 34 | 5.2,4.1,1.5,0.1,0 35 | 5.5,4.2,1.4,0.2,0 36 | 4.9,3.1,1.5,0.1,0 37 | 5.0,3.2,1.2,0.2,0 38 | 5.5,3.5,1.3,0.2,0 39 | 4.9,3.1,1.5,0.1,0 40 | 4.4,3.0,1.3,0.2,0 41 | 5.1,3.4,1.5,0.2,0 42 | 5.0,3.5,1.3,0.3,0 43 | 4.5,2.3,1.3,0.3,0 44 | 4.4,3.2,1.3,0.2,0 45 | 5.0,3.5,1.6,0.6,0 46 | 5.1,3.8,1.9,0.4,0 47 | 4.8,3.0,1.4,0.3,0 48 | 5.1,3.8,1.6,0.2,0 49 | 4.6,3.2,1.4,0.2,0 50 | 5.3,3.7,1.5,0.2,0 51 | 5.0,3.3,1.4,0.2,0 52 | 7.0,3.2,4.7,1.4,1 53 | 6.4,3.2,4.5,1.5,1 54 | 6.9,3.1,4.9,1.5,1 55 | 5.5,2.3,4.0,1.3,1 56 | 6.5,2.8,4.6,1.5,1 57 | 5.7,2.8,4.5,1.3,1 58 | 6.3,3.3,4.7,1.6,1 59 | 4.9,2.4,3.3,1.0,1 60 | 6.6,2.9,4.6,1.3,1 61 | 5.2,2.7,3.9,1.4,1 62 | 5.0,2.0,3.5,1.0,1 63 | 5.9,3.0,4.2,1.5,1 64 | 6.0,2.2,4.0,1.0,1 65 | 6.1,2.9,4.7,1.4,1 66 | 5.6,2.9,3.6,1.3,1 67 | 6.7,3.1,4.4,1.4,1 68 | 5.6,3.0,4.5,1.5,1 69 | 5.8,2.7,4.1,1.0,1 70 | 6.2,2.2,4.5,1.5,1 71 | 5.6,2.5,3.9,1.1,1 72 | 5.9,3.2,4.8,1.8,1 73 | 6.1,2.8,4.0,1.3,1 74 | 6.3,2.5,4.9,1.5,1 75 | 6.1,2.8,4.7,1.2,1 76 | 6.4,2.9,4.3,1.3,1 77 | 6.6,3.0,4.4,1.4,1 78 | 6.8,2.8,4.8,1.4,1 79 | 6.7,3.0,5.0,1.7,1 80 | 6.0,2.9,4.5,1.5,1 81 | 5.7,2.6,3.5,1.0,1 82 | 5.5,2.4,3.8,1.1,1 83 | 5.5,2.4,3.7,1.0,1 84 | 5.8,2.7,3.9,1.2,1 85 | 6.0,2.7,5.1,1.6,1 86 | 5.4,3.0,4.5,1.5,1 87 | 6.0,3.4,4.5,1.6,1 88 | 6.7,3.1,4.7,1.5,1 89 | 6.3,2.3,4.4,1.3,1 90 | 5.6,3.0,4.1,1.3,1 91 | 5.5,2.5,4.0,1.3,1 92 | 5.5,2.6,4.4,1.2,1 93 | 6.1,3.0,4.6,1.4,1 94 | 5.8,2.6,4.0,1.2,1 95 | 5.0,2.3,3.3,1.0,1 96 | 5.6,2.7,4.2,1.3,1 97 | 5.7,3.0,4.2,1.2,1 98 | 5.7,2.9,4.2,1.3,1 99 | 6.2,2.9,4.3,1.3,1 100 | 5.1,2.5,3.0,1.1,1 101 | 5.7,2.8,4.1,1.3,1 102 | 6.3,3.3,6.0,2.5,2 103 | 5.8,2.7,5.1,1.9,2 104 | 7.1,3.0,5.9,2.1,2 105 | 6.3,2.9,5.6,1.8,2 106 | 6.5,3.0,5.8,2.2,2 107 | 7.6,3.0,6.6,2.1,2 108 | 4.9,2.5,4.5,1.7,2 109 | 7.3,2.9,6.3,1.8,2 110 | 6.7,2.5,5.8,1.8,2 111 | 7.2,3.6,6.1,2.5,2 112 | 6.5,3.2,5.1,2.0,2 113 | 6.4,2.7,5.3,1.9,2 114 | 6.8,3.0,5.5,2.1,2 115 | 5.7,2.5,5.0,2.0,2 116 | 5.8,2.8,5.1,2.4,2 117 | 6.4,3.2,5.3,2.3,2 118 | 6.5,3.0,5.5,1.8,2 119 | 7.7,3.8,6.7,2.2,2 120 | 7.7,2.6,6.9,2.3,2 121 | 6.0,2.2,5.0,1.5,2 122 | 6.9,3.2,5.7,2.3,2 123 | 5.6,2.8,4.9,2.0,2 124 | 7.7,2.8,6.7,2.0,2 125 | 6.3,2.7,4.9,1.8,2 126 | 6.7,3.3,5.7,2.1,2 127 | 7.2,3.2,6.0,1.8,2 128 | 6.2,2.8,4.8,1.8,2 129 | 6.1,3.0,4.9,1.8,2 130 | 6.4,2.8,5.6,2.1,2 131 | 7.2,3.0,5.8,1.6,2 132 | 7.4,2.8,6.1,1.9,2 133 | 7.9,3.8,6.4,2.0,2 134 | 6.4,2.8,5.6,2.2,2 135 | 6.3,2.8,5.1,1.5,2 136 | 6.1,2.6,5.6,1.4,2 137 | 7.7,3.0,6.1,2.3,2 138 | 6.3,3.4,5.6,2.4,2 139 | 6.4,3.1,5.5,1.8,2 140 | 6.0,3.0,4.8,1.8,2 141 | 6.9,3.1,5.4,2.1,2 142 | 6.7,3.1,5.6,2.4,2 143 | 6.9,3.1,5.1,2.3,2 144 | 5.8,2.7,5.1,1.9,2 145 | 6.8,3.2,5.9,2.3,2 146 | 6.7,3.3,5.7,2.5,2 147 | 6.7,3.0,5.2,2.3,2 148 | 6.3,2.5,5.0,1.9,2 149 | 6.5,3.0,5.2,2.0,2 150 | 6.2,3.4,5.4,2.3,2 151 | 5.9,3.0,5.1,1.8,2 152 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/iris.csv: -------------------------------------------------------------------------------- 1 | 150,4,setosa,versicolor,virginica 2 | 5.1,3.5,1.4,0.2,0 3 | 4.9,3.0,1.4,0.2,0 4 | 4.7,3.2,1.3,0.2,0 5 | 4.6,3.1,1.5,0.2,0 6 | 5.0,3.6,1.4,0.2,0 7 | 5.4,3.9,1.7,0.4,0 8 | 4.6,3.4,1.4,0.3,0 9 | 5.0,3.4,1.5,0.2,0 10 | 4.4,2.9,1.4,0.2,0 11 | 4.9,3.1,1.5,0.1,0 12 | 5.4,3.7,1.5,0.2,0 13 | 4.8,3.4,1.6,0.2,0 14 | 4.8,3.0,1.4,0.1,0 15 | 4.3,3.0,1.1,0.1,0 16 | 5.8,4.0,1.2,0.2,0 17 | 5.7,4.4,1.5,0.4,0 18 | 5.4,3.9,1.3,0.4,0 19 | 5.1,3.5,1.4,0.3,0 20 | 5.7,3.8,1.7,0.3,0 21 | 5.1,3.8,1.5,0.3,0 22 | 5.4,3.4,1.7,0.2,0 23 | 5.1,3.7,1.5,0.4,0 24 | 4.6,3.6,1.0,0.2,0 25 | 5.1,3.3,1.7,0.5,0 26 | 4.8,3.4,1.9,0.2,0 27 | 5.0,3.0,1.6,0.2,0 28 | 5.0,3.4,1.6,0.4,0 29 | 5.2,3.5,1.5,0.2,0 30 | 5.2,3.4,1.4,0.2,0 31 | 4.7,3.2,1.6,0.2,0 32 | 4.8,3.1,1.6,0.2,0 33 | 5.4,3.4,1.5,0.4,0 34 | 5.2,4.1,1.5,0.1,0 35 | 5.5,4.2,1.4,0.2,0 36 | 4.9,3.1,1.5,0.1,0 37 | 5.0,3.2,1.2,0.2,0 38 | 5.5,3.5,1.3,0.2,0 39 | 4.9,3.1,1.5,0.1,0 40 | 4.4,3.0,1.3,0.2,0 41 | 5.1,3.4,1.5,0.2,0 42 | 5.0,3.5,1.3,0.3,0 43 | 4.5,2.3,1.3,0.3,0 44 | 4.4,3.2,1.3,0.2,0 45 | 5.0,3.5,1.6,0.6,0 46 | 5.1,3.8,1.9,0.4,0 47 | 4.8,3.0,1.4,0.3,0 48 | 5.1,3.8,1.6,0.2,0 49 | 4.6,3.2,1.4,0.2,0 50 | 5.3,3.7,1.5,0.2,0 51 | 5.0,3.3,1.4,0.2,0 52 | 7.0,3.2,4.7,1.4,1 53 | 6.4,3.2,4.5,1.5,1 54 | 6.9,3.1,4.9,1.5,1 55 | 5.5,2.3,4.0,1.3,1 56 | 6.5,2.8,4.6,1.5,1 57 | 5.7,2.8,4.5,1.3,1 58 | 6.3,3.3,4.7,1.6,1 59 | 4.9,2.4,3.3,1.0,1 60 | 6.6,2.9,4.6,1.3,1 61 | 5.2,2.7,3.9,1.4,1 62 | 5.0,2.0,3.5,1.0,1 63 | 5.9,3.0,4.2,1.5,1 64 | 6.0,2.2,4.0,1.0,1 65 | 6.1,2.9,4.7,1.4,1 66 | 5.6,2.9,3.6,1.3,1 67 | 6.7,3.1,4.4,1.4,1 68 | 5.6,3.0,4.5,1.5,1 69 | 5.8,2.7,4.1,1.0,1 70 | 6.2,2.2,4.5,1.5,1 71 | 5.6,2.5,3.9,1.1,1 72 | 5.9,3.2,4.8,1.8,1 73 | 6.1,2.8,4.0,1.3,1 74 | 6.3,2.5,4.9,1.5,1 75 | 6.1,2.8,4.7,1.2,1 76 | 6.4,2.9,4.3,1.3,1 77 | 6.6,3.0,4.4,1.4,1 78 | 6.8,2.8,4.8,1.4,1 79 | 6.7,3.0,5.0,1.7,1 80 | 6.0,2.9,4.5,1.5,1 81 | 5.7,2.6,3.5,1.0,1 82 | 5.5,2.4,3.8,1.1,1 83 | 5.5,2.4,3.7,1.0,1 84 | 5.8,2.7,3.9,1.2,1 85 | 6.0,2.7,5.1,1.6,1 86 | 5.4,3.0,4.5,1.5,1 87 | 6.0,3.4,4.5,1.6,1 88 | 6.7,3.1,4.7,1.5,1 89 | 6.3,2.3,4.4,1.3,1 90 | 5.6,3.0,4.1,1.3,1 91 | 5.5,2.5,4.0,1.3,1 92 | 5.5,2.6,4.4,1.2,1 93 | 6.1,3.0,4.6,1.4,1 94 | 5.8,2.6,4.0,1.2,1 95 | 5.0,2.3,3.3,1.0,1 96 | 5.6,2.7,4.2,1.3,1 97 | 5.7,3.0,4.2,1.2,1 98 | 5.7,2.9,4.2,1.3,1 99 | 6.2,2.9,4.3,1.3,1 100 | 5.1,2.5,3.0,1.1,1 101 | 5.7,2.8,4.1,1.3,1 102 | 6.3,3.3,6.0,2.5,2 103 | 5.8,2.7,5.1,1.9,2 104 | 7.1,3.0,5.9,2.1,2 105 | 6.3,2.9,5.6,1.8,2 106 | 6.5,3.0,5.8,2.2,2 107 | 7.6,3.0,6.6,2.1,2 108 | 4.9,2.5,4.5,1.7,2 109 | 7.3,2.9,6.3,1.8,2 110 | 6.7,2.5,5.8,1.8,2 111 | 7.2,3.6,6.1,2.5,2 112 | 6.5,3.2,5.1,2.0,2 113 | 6.4,2.7,5.3,1.9,2 114 | 6.8,3.0,5.5,2.1,2 115 | 5.7,2.5,5.0,2.0,2 116 | 5.8,2.8,5.1,2.4,2 117 | 6.4,3.2,5.3,2.3,2 118 | 6.5,3.0,5.5,1.8,2 119 | 7.7,3.8,6.7,2.2,2 120 | 7.7,2.6,6.9,2.3,2 121 | 6.0,2.2,5.0,1.5,2 122 | 6.9,3.2,5.7,2.3,2 123 | 5.6,2.8,4.9,2.0,2 124 | 7.7,2.8,6.7,2.0,2 125 | 6.3,2.7,4.9,1.8,2 126 | 6.7,3.3,5.7,2.1,2 127 | 7.2,3.2,6.0,1.8,2 128 | 6.2,2.8,4.8,1.8,2 129 | 6.1,3.0,4.9,1.8,2 130 | 6.4,2.8,5.6,2.1,2 131 | 7.2,3.0,5.8,1.6,2 132 | 7.4,2.8,6.1,1.9,2 133 | 7.9,3.8,6.4,2.0,2 134 | 6.4,2.8,5.6,2.2,2 135 | 6.3,2.8,5.1,1.5,2 136 | 6.1,2.6,5.6,1.4,2 137 | 7.7,3.0,6.1,2.3,2 138 | 6.3,3.4,5.6,2.4,2 139 | 6.4,3.1,5.5,1.8,2 140 | 6.0,3.0,4.8,1.8,2 141 | 6.9,3.1,5.4,2.1,2 142 | 6.7,3.1,5.6,2.4,2 143 | 6.9,3.1,5.1,2.3,2 144 | 5.8,2.7,5.1,1.9,2 145 | 6.8,3.2,5.9,2.3,2 146 | 6.7,3.3,5.7,2.5,2 147 | 6.7,3.0,5.2,2.3,2 148 | 6.3,2.5,5.0,1.9,2 149 | 6.5,3.0,5.2,2.0,2 150 | 6.2,3.4,5.4,2.3,2 151 | 5.9,3.0,5.1,1.8,2 152 | -------------------------------------------------------------------------------- /Day 1/4. Numpy and Pandas/iris.csv: -------------------------------------------------------------------------------- 1 | 150,4,setosa,versicolor,virginica 2 | 5.1,3.5,1.4,0.2,0 3 | 4.9,3.0,1.4,0.2,0 4 | 4.7,3.2,1.3,0.2,0 5 | 4.6,3.1,1.5,0.2,0 6 | 5.0,3.6,1.4,0.2,0 7 | 5.4,3.9,1.7,0.4,0 8 | 4.6,3.4,1.4,0.3,0 9 | 5.0,3.4,1.5,0.2,0 10 | 4.4,2.9,1.4,0.2,0 11 | 4.9,3.1,1.5,0.1,0 12 | 5.4,3.7,1.5,0.2,0 13 | 4.8,3.4,1.6,0.2,0 14 | 4.8,3.0,1.4,0.1,0 15 | 4.3,3.0,1.1,0.1,0 16 | 5.8,4.0,1.2,0.2,0 17 | 5.7,4.4,1.5,0.4,0 18 | 5.4,3.9,1.3,0.4,0 19 | 5.1,3.5,1.4,0.3,0 20 | 5.7,3.8,1.7,0.3,0 21 | 5.1,3.8,1.5,0.3,0 22 | 5.4,3.4,1.7,0.2,0 23 | 5.1,3.7,1.5,0.4,0 24 | 4.6,3.6,1.0,0.2,0 25 | 5.1,3.3,1.7,0.5,0 26 | 4.8,3.4,1.9,0.2,0 27 | 5.0,3.0,1.6,0.2,0 28 | 5.0,3.4,1.6,0.4,0 29 | 5.2,3.5,1.5,0.2,0 30 | 5.2,3.4,1.4,0.2,0 31 | 4.7,3.2,1.6,0.2,0 32 | 4.8,3.1,1.6,0.2,0 33 | 5.4,3.4,1.5,0.4,0 34 | 5.2,4.1,1.5,0.1,0 35 | 5.5,4.2,1.4,0.2,0 36 | 4.9,3.1,1.5,0.1,0 37 | 5.0,3.2,1.2,0.2,0 38 | 5.5,3.5,1.3,0.2,0 39 | 4.9,3.1,1.5,0.1,0 40 | 4.4,3.0,1.3,0.2,0 41 | 5.1,3.4,1.5,0.2,0 42 | 5.0,3.5,1.3,0.3,0 43 | 4.5,2.3,1.3,0.3,0 44 | 4.4,3.2,1.3,0.2,0 45 | 5.0,3.5,1.6,0.6,0 46 | 5.1,3.8,1.9,0.4,0 47 | 4.8,3.0,1.4,0.3,0 48 | 5.1,3.8,1.6,0.2,0 49 | 4.6,3.2,1.4,0.2,0 50 | 5.3,3.7,1.5,0.2,0 51 | 5.0,3.3,1.4,0.2,0 52 | 7.0,3.2,4.7,1.4,1 53 | 6.4,3.2,4.5,1.5,1 54 | 6.9,3.1,4.9,1.5,1 55 | 5.5,2.3,4.0,1.3,1 56 | 6.5,2.8,4.6,1.5,1 57 | 5.7,2.8,4.5,1.3,1 58 | 6.3,3.3,4.7,1.6,1 59 | 4.9,2.4,3.3,1.0,1 60 | 6.6,2.9,4.6,1.3,1 61 | 5.2,2.7,3.9,1.4,1 62 | 5.0,2.0,3.5,1.0,1 63 | 5.9,3.0,4.2,1.5,1 64 | 6.0,2.2,4.0,1.0,1 65 | 6.1,2.9,4.7,1.4,1 66 | 5.6,2.9,3.6,1.3,1 67 | 6.7,3.1,4.4,1.4,1 68 | 5.6,3.0,4.5,1.5,1 69 | 5.8,2.7,4.1,1.0,1 70 | 6.2,2.2,4.5,1.5,1 71 | 5.6,2.5,3.9,1.1,1 72 | 5.9,3.2,4.8,1.8,1 73 | 6.1,2.8,4.0,1.3,1 74 | 6.3,2.5,4.9,1.5,1 75 | 6.1,2.8,4.7,1.2,1 76 | 6.4,2.9,4.3,1.3,1 77 | 6.6,3.0,4.4,1.4,1 78 | 6.8,2.8,4.8,1.4,1 79 | 6.7,3.0,5.0,1.7,1 80 | 6.0,2.9,4.5,1.5,1 81 | 5.7,2.6,3.5,1.0,1 82 | 5.5,2.4,3.8,1.1,1 83 | 5.5,2.4,3.7,1.0,1 84 | 5.8,2.7,3.9,1.2,1 85 | 6.0,2.7,5.1,1.6,1 86 | 5.4,3.0,4.5,1.5,1 87 | 6.0,3.4,4.5,1.6,1 88 | 6.7,3.1,4.7,1.5,1 89 | 6.3,2.3,4.4,1.3,1 90 | 5.6,3.0,4.1,1.3,1 91 | 5.5,2.5,4.0,1.3,1 92 | 5.5,2.6,4.4,1.2,1 93 | 6.1,3.0,4.6,1.4,1 94 | 5.8,2.6,4.0,1.2,1 95 | 5.0,2.3,3.3,1.0,1 96 | 5.6,2.7,4.2,1.3,1 97 | 5.7,3.0,4.2,1.2,1 98 | 5.7,2.9,4.2,1.3,1 99 | 6.2,2.9,4.3,1.3,1 100 | 5.1,2.5,3.0,1.1,1 101 | 5.7,2.8,4.1,1.3,1 102 | 6.3,3.3,6.0,2.5,2 103 | 5.8,2.7,5.1,1.9,2 104 | 7.1,3.0,5.9,2.1,2 105 | 6.3,2.9,5.6,1.8,2 106 | 6.5,3.0,5.8,2.2,2 107 | 7.6,3.0,6.6,2.1,2 108 | 4.9,2.5,4.5,1.7,2 109 | 7.3,2.9,6.3,1.8,2 110 | 6.7,2.5,5.8,1.8,2 111 | 7.2,3.6,6.1,2.5,2 112 | 6.5,3.2,5.1,2.0,2 113 | 6.4,2.7,5.3,1.9,2 114 | 6.8,3.0,5.5,2.1,2 115 | 5.7,2.5,5.0,2.0,2 116 | 5.8,2.8,5.1,2.4,2 117 | 6.4,3.2,5.3,2.3,2 118 | 6.5,3.0,5.5,1.8,2 119 | 7.7,3.8,6.7,2.2,2 120 | 7.7,2.6,6.9,2.3,2 121 | 6.0,2.2,5.0,1.5,2 122 | 6.9,3.2,5.7,2.3,2 123 | 5.6,2.8,4.9,2.0,2 124 | 7.7,2.8,6.7,2.0,2 125 | 6.3,2.7,4.9,1.8,2 126 | 6.7,3.3,5.7,2.1,2 127 | 7.2,3.2,6.0,1.8,2 128 | 6.2,2.8,4.8,1.8,2 129 | 6.1,3.0,4.9,1.8,2 130 | 6.4,2.8,5.6,2.1,2 131 | 7.2,3.0,5.8,1.6,2 132 | 7.4,2.8,6.1,1.9,2 133 | 7.9,3.8,6.4,2.0,2 134 | 6.4,2.8,5.6,2.2,2 135 | 6.3,2.8,5.1,1.5,2 136 | 6.1,2.6,5.6,1.4,2 137 | 7.7,3.0,6.1,2.3,2 138 | 6.3,3.4,5.6,2.4,2 139 | 6.4,3.1,5.5,1.8,2 140 | 6.0,3.0,4.8,1.8,2 141 | 6.9,3.1,5.4,2.1,2 142 | 6.7,3.1,5.6,2.4,2 143 | 6.9,3.1,5.1,2.3,2 144 | 5.8,2.7,5.1,1.9,2 145 | 6.8,3.2,5.9,2.3,2 146 | 6.7,3.3,5.7,2.5,2 147 | 6.7,3.0,5.2,2.3,2 148 | 6.3,2.5,5.0,1.9,2 149 | 6.5,3.0,5.2,2.0,2 150 | 6.2,3.4,5.4,2.3,2 151 | 5.9,3.0,5.1,1.8,2 152 | -------------------------------------------------------------------------------- /Day 1/5. Machine Learning Hello World/iris.csv: -------------------------------------------------------------------------------- 1 | 150,4,setosa,versicolor,virginica 2 | 5.1,3.5,1.4,0.2,0 3 | 4.9,3.0,1.4,0.2,0 4 | 4.7,3.2,1.3,0.2,0 5 | 4.6,3.1,1.5,0.2,0 6 | 5.0,3.6,1.4,0.2,0 7 | 5.4,3.9,1.7,0.4,0 8 | 4.6,3.4,1.4,0.3,0 9 | 5.0,3.4,1.5,0.2,0 10 | 4.4,2.9,1.4,0.2,0 11 | 4.9,3.1,1.5,0.1,0 12 | 5.4,3.7,1.5,0.2,0 13 | 4.8,3.4,1.6,0.2,0 14 | 4.8,3.0,1.4,0.1,0 15 | 4.3,3.0,1.1,0.1,0 16 | 5.8,4.0,1.2,0.2,0 17 | 5.7,4.4,1.5,0.4,0 18 | 5.4,3.9,1.3,0.4,0 19 | 5.1,3.5,1.4,0.3,0 20 | 5.7,3.8,1.7,0.3,0 21 | 5.1,3.8,1.5,0.3,0 22 | 5.4,3.4,1.7,0.2,0 23 | 5.1,3.7,1.5,0.4,0 24 | 4.6,3.6,1.0,0.2,0 25 | 5.1,3.3,1.7,0.5,0 26 | 4.8,3.4,1.9,0.2,0 27 | 5.0,3.0,1.6,0.2,0 28 | 5.0,3.4,1.6,0.4,0 29 | 5.2,3.5,1.5,0.2,0 30 | 5.2,3.4,1.4,0.2,0 31 | 4.7,3.2,1.6,0.2,0 32 | 4.8,3.1,1.6,0.2,0 33 | 5.4,3.4,1.5,0.4,0 34 | 5.2,4.1,1.5,0.1,0 35 | 5.5,4.2,1.4,0.2,0 36 | 4.9,3.1,1.5,0.1,0 37 | 5.0,3.2,1.2,0.2,0 38 | 5.5,3.5,1.3,0.2,0 39 | 4.9,3.1,1.5,0.1,0 40 | 4.4,3.0,1.3,0.2,0 41 | 5.1,3.4,1.5,0.2,0 42 | 5.0,3.5,1.3,0.3,0 43 | 4.5,2.3,1.3,0.3,0 44 | 4.4,3.2,1.3,0.2,0 45 | 5.0,3.5,1.6,0.6,0 46 | 5.1,3.8,1.9,0.4,0 47 | 4.8,3.0,1.4,0.3,0 48 | 5.1,3.8,1.6,0.2,0 49 | 4.6,3.2,1.4,0.2,0 50 | 5.3,3.7,1.5,0.2,0 51 | 5.0,3.3,1.4,0.2,0 52 | 7.0,3.2,4.7,1.4,1 53 | 6.4,3.2,4.5,1.5,1 54 | 6.9,3.1,4.9,1.5,1 55 | 5.5,2.3,4.0,1.3,1 56 | 6.5,2.8,4.6,1.5,1 57 | 5.7,2.8,4.5,1.3,1 58 | 6.3,3.3,4.7,1.6,1 59 | 4.9,2.4,3.3,1.0,1 60 | 6.6,2.9,4.6,1.3,1 61 | 5.2,2.7,3.9,1.4,1 62 | 5.0,2.0,3.5,1.0,1 63 | 5.9,3.0,4.2,1.5,1 64 | 6.0,2.2,4.0,1.0,1 65 | 6.1,2.9,4.7,1.4,1 66 | 5.6,2.9,3.6,1.3,1 67 | 6.7,3.1,4.4,1.4,1 68 | 5.6,3.0,4.5,1.5,1 69 | 5.8,2.7,4.1,1.0,1 70 | 6.2,2.2,4.5,1.5,1 71 | 5.6,2.5,3.9,1.1,1 72 | 5.9,3.2,4.8,1.8,1 73 | 6.1,2.8,4.0,1.3,1 74 | 6.3,2.5,4.9,1.5,1 75 | 6.1,2.8,4.7,1.2,1 76 | 6.4,2.9,4.3,1.3,1 77 | 6.6,3.0,4.4,1.4,1 78 | 6.8,2.8,4.8,1.4,1 79 | 6.7,3.0,5.0,1.7,1 80 | 6.0,2.9,4.5,1.5,1 81 | 5.7,2.6,3.5,1.0,1 82 | 5.5,2.4,3.8,1.1,1 83 | 5.5,2.4,3.7,1.0,1 84 | 5.8,2.7,3.9,1.2,1 85 | 6.0,2.7,5.1,1.6,1 86 | 5.4,3.0,4.5,1.5,1 87 | 6.0,3.4,4.5,1.6,1 88 | 6.7,3.1,4.7,1.5,1 89 | 6.3,2.3,4.4,1.3,1 90 | 5.6,3.0,4.1,1.3,1 91 | 5.5,2.5,4.0,1.3,1 92 | 5.5,2.6,4.4,1.2,1 93 | 6.1,3.0,4.6,1.4,1 94 | 5.8,2.6,4.0,1.2,1 95 | 5.0,2.3,3.3,1.0,1 96 | 5.6,2.7,4.2,1.3,1 97 | 5.7,3.0,4.2,1.2,1 98 | 5.7,2.9,4.2,1.3,1 99 | 6.2,2.9,4.3,1.3,1 100 | 5.1,2.5,3.0,1.1,1 101 | 5.7,2.8,4.1,1.3,1 102 | 6.3,3.3,6.0,2.5,2 103 | 5.8,2.7,5.1,1.9,2 104 | 7.1,3.0,5.9,2.1,2 105 | 6.3,2.9,5.6,1.8,2 106 | 6.5,3.0,5.8,2.2,2 107 | 7.6,3.0,6.6,2.1,2 108 | 4.9,2.5,4.5,1.7,2 109 | 7.3,2.9,6.3,1.8,2 110 | 6.7,2.5,5.8,1.8,2 111 | 7.2,3.6,6.1,2.5,2 112 | 6.5,3.2,5.1,2.0,2 113 | 6.4,2.7,5.3,1.9,2 114 | 6.8,3.0,5.5,2.1,2 115 | 5.7,2.5,5.0,2.0,2 116 | 5.8,2.8,5.1,2.4,2 117 | 6.4,3.2,5.3,2.3,2 118 | 6.5,3.0,5.5,1.8,2 119 | 7.7,3.8,6.7,2.2,2 120 | 7.7,2.6,6.9,2.3,2 121 | 6.0,2.2,5.0,1.5,2 122 | 6.9,3.2,5.7,2.3,2 123 | 5.6,2.8,4.9,2.0,2 124 | 7.7,2.8,6.7,2.0,2 125 | 6.3,2.7,4.9,1.8,2 126 | 6.7,3.3,5.7,2.1,2 127 | 7.2,3.2,6.0,1.8,2 128 | 6.2,2.8,4.8,1.8,2 129 | 6.1,3.0,4.9,1.8,2 130 | 6.4,2.8,5.6,2.1,2 131 | 7.2,3.0,5.8,1.6,2 132 | 7.4,2.8,6.1,1.9,2 133 | 7.9,3.8,6.4,2.0,2 134 | 6.4,2.8,5.6,2.2,2 135 | 6.3,2.8,5.1,1.5,2 136 | 6.1,2.6,5.6,1.4,2 137 | 7.7,3.0,6.1,2.3,2 138 | 6.3,3.4,5.6,2.4,2 139 | 6.4,3.1,5.5,1.8,2 140 | 6.0,3.0,4.8,1.8,2 141 | 6.9,3.1,5.4,2.1,2 142 | 6.7,3.1,5.6,2.4,2 143 | 6.9,3.1,5.1,2.3,2 144 | 5.8,2.7,5.1,1.9,2 145 | 6.8,3.2,5.9,2.3,2 146 | 6.7,3.3,5.7,2.5,2 147 | 6.7,3.0,5.2,2.3,2 148 | 6.3,2.5,5.0,1.9,2 149 | 6.5,3.0,5.2,2.0,2 150 | 6.2,3.4,5.4,2.3,2 151 | 5.9,3.0,5.1,1.8,2 152 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/1. Stdin.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Standard input in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 5, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "4\n", 20 | "4\n" 21 | ] 22 | } 23 | ], 24 | "source": [ 25 | "a = input()\n", 26 | "print(a)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "data": { 36 | "text/plain": [ 37 | "str" 38 | ] 39 | }, 40 | "execution_count": 2, 41 | "metadata": {}, 42 | "output_type": "execute_result" 43 | } 44 | ], 45 | "source": [ 46 | "type(a)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 4, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "4\n", 59 | "4 , \n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "a = int(input())\n", 65 | "print(a, ', ', type(a))" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 6, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "Enter something: Hello\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "a = input('Enter something: ')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "## What if we want to enter a list\n", 90 | "### space separated list" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 7, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "Enter somethingHello World\n", 103 | "Hello World\n", 104 | "['Hello', 'World']\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "inp = input('Enter something')\n", 110 | "print(inp)\n", 111 | "\n", 112 | "lst = inp.split()\n", 113 | "print(lst)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 9, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "Enter Something: Hello World\n", 126 | "['Hello', 'World']\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "lst = input('Enter Something: ').split()\n", 132 | "print(lst)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "metadata": {}, 138 | "source": [ 139 | "### Comma separated" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 10, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "name": "stdout", 149 | "output_type": "stream", 150 | "text": [ 151 | "Enter values1, 2, 3, 4\n", 152 | "['1', '2', '3', '4']\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "lst = input('Enter values').split(', ')\n", 158 | "print(lst)" 159 | ] 160 | } 161 | ], 162 | "metadata": { 163 | "kernelspec": { 164 | "display_name": "Python 3", 165 | "language": "python", 166 | "name": "python3" 167 | }, 168 | "language_info": { 169 | "codemirror_mode": { 170 | "name": "ipython", 171 | "version": 3 172 | }, 173 | "file_extension": ".py", 174 | "mimetype": "text/x-python", 175 | "name": "python", 176 | "nbconvert_exporter": "python", 177 | "pygments_lexer": "ipython3", 178 | "version": "3.6.4" 179 | } 180 | }, 181 | "nbformat": 4, 182 | "nbformat_minor": 2 183 | } 184 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/.ipynb_checkpoints/Stdin-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Standard input in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 5, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "4\n", 20 | "4\n" 21 | ] 22 | } 23 | ], 24 | "source": [ 25 | "a = input()\n", 26 | "print(a)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "data": { 36 | "text/plain": [ 37 | "str" 38 | ] 39 | }, 40 | "execution_count": 2, 41 | "metadata": {}, 42 | "output_type": "execute_result" 43 | } 44 | ], 45 | "source": [ 46 | "type(a)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 4, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "4\n", 59 | "4 , \n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "a = int(input())\n", 65 | "print(a, ', ', type(a))" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 6, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "Enter something: Hello\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "a = input('Enter something: ')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "## What if we want to enter a list\n", 90 | "### space separated list" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 7, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "Enter somethingHello World\n", 103 | "Hello World\n", 104 | "['Hello', 'World']\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "inp = input('Enter something')\n", 110 | "print(inp)\n", 111 | "\n", 112 | "lst = inp.split()\n", 113 | "print(lst)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 9, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "Enter Something: Hello World\n", 126 | "['Hello', 'World']\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "lst = input('Enter Something: ').split()\n", 132 | "print(lst)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "metadata": {}, 138 | "source": [ 139 | "### Comma separated" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 10, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "name": "stdout", 149 | "output_type": "stream", 150 | "text": [ 151 | "Enter values1, 2, 3, 4\n", 152 | "['1', '2', '3', '4']\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "lst = input('Enter values').split(', ')\n", 158 | "print(lst)" 159 | ] 160 | } 161 | ], 162 | "metadata": { 163 | "kernelspec": { 164 | "display_name": "Python 3", 165 | "language": "python", 166 | "name": "python3" 167 | }, 168 | "language_info": { 169 | "codemirror_mode": { 170 | "name": "ipython", 171 | "version": 3 172 | }, 173 | "file_extension": ".py", 174 | "mimetype": "text/x-python", 175 | "name": "python", 176 | "nbconvert_exporter": "python", 177 | "pygments_lexer": "ipython3", 178 | "version": "3.6.4" 179 | } 180 | }, 181 | "nbformat": 4, 182 | "nbformat_minor": 2 183 | } 184 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/4. Iteration.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Loops and Iterators" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## The while loop" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 16, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "0 1 2 3 4 " 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "i = 0\n", 32 | "while i < 5:\n", 33 | " print(i, end = ' ')\n", 34 | " i += 1" 35 | ] 36 | }, 37 | { 38 | "cell_type": "raw", 39 | "metadata": {}, 40 | "source": [ 41 | "while expression:\n", 42 | " statements\n", 43 | " modify loop control variable" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## For Loop" 51 | ] 52 | }, 53 | { 54 | "cell_type": "raw", 55 | "metadata": {}, 56 | "source": [ 57 | "for iterator_variable in collection:\n", 58 | " statements" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "1 2 4 6 " 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "a = [1, 2, 4, 6]\n", 76 | "\n", 77 | "for i in a:\n", 78 | " print(i, end = ' ')" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## The Range Function" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "The range function has two arguments - first and last value, the first value is 0 by default\n", 93 | "\n", 94 | "last value is not included in range" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 15, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "0 1 2 3 4 " 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "for x in range(5):\n", 112 | " print(x, end = ' ')" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 14, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "1 2 3 " 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "for x in range(1, 4):\n", 130 | " print(x, end = ' ')" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "### Break and Continue statements" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 13, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "0 1 2 3 4 " 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "for x in range(10):\n", 155 | " if x == 5:\n", 156 | " break\n", 157 | " print(x, end = ' ')" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 12, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "0 1 2 3 4 6 7 8 9 " 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "for x in range(10):\n", 175 | " if x == 5:\n", 176 | " continue\n", 177 | " print(x, end = ' ')" 178 | ] 179 | } 180 | ], 181 | "metadata": { 182 | "kernelspec": { 183 | "display_name": "Python 3", 184 | "language": "python", 185 | "name": "python3" 186 | }, 187 | "language_info": { 188 | "codemirror_mode": { 189 | "name": "ipython", 190 | "version": 3 191 | }, 192 | "file_extension": ".py", 193 | "mimetype": "text/x-python", 194 | "name": "python", 195 | "nbconvert_exporter": "python", 196 | "pygments_lexer": "ipython3", 197 | "version": "3.6.4" 198 | } 199 | }, 200 | "nbformat": 4, 201 | "nbformat_minor": 2 202 | } 203 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/.ipynb_checkpoints/Iteration-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Loops and Iterators" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## The while loop" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 16, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "0 1 2 3 4 " 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "i = 0\n", 32 | "while i < 5:\n", 33 | " print(i, end = ' ')\n", 34 | " i += 1" 35 | ] 36 | }, 37 | { 38 | "cell_type": "raw", 39 | "metadata": {}, 40 | "source": [ 41 | "while expression:\n", 42 | " statements\n", 43 | " modify loop control variable" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## For Loop" 51 | ] 52 | }, 53 | { 54 | "cell_type": "raw", 55 | "metadata": {}, 56 | "source": [ 57 | "for iterator_variable in collection:\n", 58 | " statements" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "1 2 4 6 " 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "a = [1, 2, 4, 6]\n", 76 | "\n", 77 | "for i in a:\n", 78 | " print(i, end = ' ')" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## The Range Function" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "The range function has two arguments - first and last value, the first value is 0 by default\n", 93 | "\n", 94 | "last value is not included in range" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 15, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "0 1 2 3 4 " 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "for x in range(5):\n", 112 | " print(x, end = ' ')" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 14, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "1 2 3 " 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "for x in range(1, 4):\n", 130 | " print(x, end = ' ')" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "### Break and Continue statements" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 13, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "0 1 2 3 4 " 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "for x in range(10):\n", 155 | " if x == 5:\n", 156 | " break\n", 157 | " print(x, end = ' ')" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 12, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "0 1 2 3 4 6 7 8 9 " 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "for x in range(10):\n", 175 | " if x == 5:\n", 176 | " continue\n", 177 | " print(x, end = ' ')" 178 | ] 179 | } 180 | ], 181 | "metadata": { 182 | "kernelspec": { 183 | "display_name": "Python 3", 184 | "language": "python", 185 | "name": "python3" 186 | }, 187 | "language_info": { 188 | "codemirror_mode": { 189 | "name": "ipython", 190 | "version": 3 191 | }, 192 | "file_extension": ".py", 193 | "mimetype": "text/x-python", 194 | "name": "python", 195 | "nbconvert_exporter": "python", 196 | "pygments_lexer": "ipython3", 197 | "version": "3.6.4" 198 | } 199 | }, 200 | "nbformat": 4, 201 | "nbformat_minor": 2 202 | } 203 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/raw_data_to_csv.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | x = [974.5803384, 5937.029525999998, 6223.367465, 4797.231267, 12779.37964, 34435.367439999995, 36126.4927, 29796.04834, 1391.253792, 33692.60508, 1441.284873, 3822.137084, 7446.298803, 12569.85177, 9065.800825, 10680.79282, 1217.032994, 430.0706916, 1713.778686, 2042.09524, 36319.23501, 706.016537, 1704.063724, 13171.63885, 4959.114854, 7006.580419, 986.1478792, 277.5518587, 3632.557798, 9645.06142, 1544.750112, 14619.222719999998, 8948.102923, 22833.30851, 35278.41874, 2082.4815670000007, 6025.3747520000015, 6873.262326000001, 5581.180998, 5728.353514, 12154.08975, 641.3695236000002, 690.8055759, 33207.0844, 30470.0167, 13206.48452, 752.7497265, 32170.37442, 1327.60891, 27538.41188, 5186.050003, 942.6542111, 579.2317429999998, 1201.637154, 3548.3308460000007, 39724.97867, 18008.94444, 36180.78919, 2452.210407, 3540.651564, 11605.71449, 4471.061906, 40675.99635, 25523.2771, 28569.7197, 7320.8802620000015, 31656.06806, 4519.461171, 1463.249282, 1593.06548, 23348.139730000006, 47306.98978, 10461.05868, 1569.331442, 414.5073415, 12057.49928, 1044.770126, 759.3499101, 12451.6558, 1042.581557, 1803.151496, 10956.99112, 11977.57496, 3095.7722710000007, 9253.896111, 3820.17523, 823.6856205, 944.0, 4811.060429, 1091.359778, 36797.93332, 25185.00911, 2749.320965, 619.6768923999998, 2013.977305, 49357.19017, 22316.19287, 2605.94758, 9809.185636, 4172.838464, 7408.905561, 3190.481016, 15389.924680000002, 20509.64777, 19328.70901, 7670.122558, 10808.47561, 863.0884639000002, 1598.435089, 21654.83194, 1712.472136, 9786.534714, 862.5407561000002, 47143.17964, 18678.31435, 25768.25759, 926.1410683, 9269.657808, 28821.0637, 3970.095407, 2602.394995, 4513.480643, 33859.74835, 37506.41907, 4184.548089, 28718.27684, 1107.482182, 7458.396326999998, 882.9699437999999, 18008.50924, 7092.923025, 8458.276384, 1056.380121, 33203.26128, 42951.65309, 10611.46299, 11415.80569, 2441.576404, 3025.349798, 2280.769906, 1271.211593, 469.70929810000007] 4 | 5 | y = [43.828, 76.423, 72.301, 42.731, 75.32, 81.235, 79.829, 75.635, 64.062, 79.441, 56.728, 65.554, 74.852, 50.728, 72.39, 73.005, 52.295, 49.58, 59.723, 50.43, 80.653, 44.74100000000001, 50.651, 78.553, 72.961, 72.889, 65.152, 46.462, 55.322, 78.782, 48.328, 75.748, 78.273, 76.486, 78.332, 54.791, 72.235, 74.994, 71.33800000000002, 71.878, 51.57899999999999, 58.04, 52.947, 79.313, 80.657, 56.735, 59.448, 79.406, 60.022, 79.483, 70.259, 56.007, 46.38800000000001, 60.916, 70.19800000000001, 82.208, 73.33800000000002, 81.757, 64.69800000000001, 70.65, 70.964, 59.545, 78.885, 80.745, 80.546, 72.567, 82.603, 72.535, 54.11, 67.297, 78.623, 77.58800000000002, 71.993, 42.592, 45.678, 73.952, 59.44300000000001, 48.303, 74.241, 54.467, 64.164, 72.801, 76.195, 66.803, 74.543, 71.164, 42.082, 62.069, 52.90600000000001, 63.785, 79.762, 80.204, 72.899, 56.867, 46.859, 80.196, 75.64, 65.483, 75.53699999999998, 71.752, 71.421, 71.688, 75.563, 78.098, 78.74600000000002, 76.442, 72.476, 46.242, 65.528, 72.777, 63.062, 74.002, 42.56800000000001, 79.972, 74.663, 77.926, 48.159, 49.339, 80.941, 72.396, 58.556, 39.613, 80.884, 81.70100000000002, 74.143, 78.4, 52.517, 70.616, 58.42, 69.819, 73.923, 71.777, 51.542, 79.425, 78.242, 76.384, 73.747, 74.249, 73.422, 62.698, 42.38399999999999, 43.487] 6 | 7 | z = [31.889923, 3.600523, 33.333216, 12.420476, 40.301927, 20.434176, 8.199783, 0.708573, 150.448339, 10.392226, 8.078314, 9.119152, 4.552198, 1.639131, 190.010647, 7.322858, 14.326203, 8.390505, 14.131858, 17.696293, 33.390141, 4.369038, 10.238807, 16.284741, 1318.683096, 44.22755, 0.71096, 64.606759, 3.80061, 4.133884, 18.013409, 4.493312, 11.416987, 10.228744, 5.46812, 0.496374, 9.319622, 13.75568, 80.264543, 6.939688, 0.551201, 4.906585, 76.511887, 5.23846, 61.083916, 1.454867, 1.688359, 82.400996, 22.873338, 10.70629, 12.572928, 9.947814, 1.472041, 8.502814, 7.483763, 6.980412, 9.956108, 0.301931, 1110.396331, 223.547, 69.45357, 27.499638, 4.109086, 6.426679, 58.147733, 2.780132, 127.467972, 6.053193, 35.610177, 23.301725, 49.04479, 2.505559, 3.921278, 2.012649, 3.193942, 6.036914, 19.167654, 13.327079, 24.821286, 12.031795, 3.270065, 1.250882, 108.700891, 2.874127, 0.684736, 33.757175, 19.951656, 47.76198, 2.05508, 28.90179, 16.570613, 4.115771, 5.675356, 12.894865, 135.031164, 4.627926, 3.204897, 169.270617, 3.242173, 6.667147, 28.674757, 91.077287, 38.518241, 10.642836, 3.942491, 0.798094, 22.276056, 8.860588, 0.199579, 27.601038, 12.267493, 10.150265, 6.144562, 4.553009, 5.447502, 2.009245, 9.118773, 43.997828, 40.448191, 20.378239, 42.292929, 1.133066, 9.031088, 7.554661, 19.314747, 23.174294, 38.13964, 65.068149, 5.701579, 1.056608, 10.276158, 71.158647, 29.170398, 60.776238, 301.139947, 3.447496, 26.084662, 85.262356, 4.018332, 22.211743, 11.746035, 12.311143] 8 | 9 | d = {'gdp_cap': x, 10 | 'life_exp': y, 11 | 'pop': z} 12 | 13 | 14 | df = pd.DataFrame(data = d) 15 | 16 | df.to_csv('example.csv') -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/2. Customisations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Customizing the plots" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "There are many types of plots and many customizations\n", 15 | "\n", 16 | "Choice depends on-\n", 17 | "\n", 18 | "1. The Data\n", 19 | "2. The story you want to tell" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import matplotlib.pyplot as plt" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "import pandas as pd" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "df = pd.read_csv('world_pop.csv', usecols = [1,2], skiprows = 1, names = ['year', 'pop'])" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "df.head()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "plt.plot(df['year'], df['pop'])" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "year = df['year']\n", 74 | "pop = df['pop']" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "type(year)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "#### Adding Title and X Y labels" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "plt.plot(year, pop)\n", 100 | "plt.title('World Population Projection')\n", 101 | "\n", 102 | "plt.xlabel('Year')\n", 103 | "plt.ylabel('Population in Billions')" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "### Shifting y axis up to start values with 0" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "plt.plot(year, pop)\n", 120 | "plt.title('World Population Projection')\n", 121 | "\n", 122 | "plt.xlabel('Year')\n", 123 | "plt.ylabel('Population in Billions')\n", 124 | "\n", 125 | "plt.yticks([0, 2, 4, 6, 8, 10])" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "### Adding meaningful tickers for y axis" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "plt.plot(year, pop)\n", 142 | "plt.title('World Population Projection')\n", 143 | "\n", 144 | "plt.xlabel('Year')\n", 145 | "plt.ylabel('Population in Billions')\n", 146 | "\n", 147 | "plt.yticks([0, 2, 4, 6, 8, 10], ['0 B', '2 B', '4 B', '6 B', '8 B', '10 B'])" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "year = [1800, 1850, 1900] + list(year)\n", 157 | "pop = [1.0, 1.262, 1.650] + list(pop)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "plt.plot(year, pop)\n", 167 | "plt.title('World Population Projection')\n", 168 | "\n", 169 | "plt.xlabel('Year')\n", 170 | "plt.ylabel('Population in Billions')\n", 171 | "\n", 172 | "plt.yticks([0, 2, 4, 6, 8, 10], ['0 B', '2 B', '4 B', '6 B', '8 B', '10 B'])" 173 | ] 174 | } 175 | ], 176 | "metadata": { 177 | "kernelspec": { 178 | "display_name": "Python 3", 179 | "language": "python", 180 | "name": "python3" 181 | }, 182 | "language_info": { 183 | "codemirror_mode": { 184 | "name": "ipython", 185 | "version": 3 186 | }, 187 | "file_extension": ".py", 188 | "mimetype": "text/x-python", 189 | "name": "python", 190 | "nbconvert_exporter": "python", 191 | "pygments_lexer": "ipython3", 192 | "version": "3.6.4" 193 | } 194 | }, 195 | "nbformat": 4, 196 | "nbformat_minor": 2 197 | } 198 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/.ipynb_checkpoints/Customisations-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Customizing the plots" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "There are many types of plots and many customizations\n", 15 | "\n", 16 | "Choice depends on-\n", 17 | "\n", 18 | "1. The Data\n", 19 | "2. The story you want to tell" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import matplotlib.pyplot as plt" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "import pandas as pd" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "df = pd.read_csv('world_pop.csv', usecols = [1,2], skiprows = 1, names = ['year', 'pop'])" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "df.head()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "plt.plot(df['year'], df['pop'])" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "year = df['year']\n", 74 | "pop = df['pop']" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "type(year)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "#### Adding Title and X Y labels" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "plt.plot(year, pop)\n", 100 | "plt.title('World Population Projection')\n", 101 | "\n", 102 | "plt.xlabel('Year')\n", 103 | "plt.ylabel('Population in Billions')" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "### Shifting y axis up to start values with 0" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "plt.plot(year, pop)\n", 120 | "plt.title('World Population Projection')\n", 121 | "\n", 122 | "plt.xlabel('Year')\n", 123 | "plt.ylabel('Population in Billions')\n", 124 | "\n", 125 | "plt.yticks([0, 2, 4, 6, 8, 10])" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "### Adding meaningful tickers for y axis" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "plt.plot(year, pop)\n", 142 | "plt.title('World Population Projection')\n", 143 | "\n", 144 | "plt.xlabel('Year')\n", 145 | "plt.ylabel('Population in Billions')\n", 146 | "\n", 147 | "plt.yticks([0, 2, 4, 6, 8, 10], ['0 B', '2 B', '4 B', '6 B', '8 B', '10 B'])" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "year = [1800, 1850, 1900] + list(year)\n", 157 | "pop = [1.0, 1.262, 1.650] + list(pop)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "plt.plot(year, pop)\n", 167 | "plt.title('World Population Projection')\n", 168 | "\n", 169 | "plt.xlabel('Year')\n", 170 | "plt.ylabel('Population in Billions')\n", 171 | "\n", 172 | "plt.yticks([0, 2, 4, 6, 8, 10], ['0 B', '2 B', '4 B', '6 B', '8 B', '10 B'])" 173 | ] 174 | } 175 | ], 176 | "metadata": { 177 | "kernelspec": { 178 | "display_name": "Python 3", 179 | "language": "python", 180 | "name": "python3" 181 | }, 182 | "language_info": { 183 | "codemirror_mode": { 184 | "name": "ipython", 185 | "version": 3 186 | }, 187 | "file_extension": ".py", 188 | "mimetype": "text/x-python", 189 | "name": "python", 190 | "nbconvert_exporter": "python", 191 | "pygments_lexer": "ipython3", 192 | "version": "3.6.4" 193 | } 194 | }, 195 | "nbformat": 4, 196 | "nbformat_minor": 2 197 | } 198 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/2. Example_BRICS.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Example BRICS Countries" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import pandas as pd" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "brics = pd.read_csv('BRICS.csv', index_col = 0)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "brics" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "brics['country']" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "type(brics['country'])" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "brics[['country']]" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "type(brics[['country']])" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "brics[['country', 'capital']]" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "brics[1:4]" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "### Square brackets work, but it has limited functionality\n", 96 | "\n", 97 | "ideally it is similar to 2D NumPy arrays\n", 98 | "\n", 99 | "np_array[row, col]\n", 100 | "\n", 101 | "\n", 102 | "### loc and iloc\n", 103 | "\n", 104 | "- loc - workss for labels\n", 105 | "- iloc - works for positions" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "brics.loc['RU']" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "#### loc returns a row as pandas series object\n", 122 | "\n", 123 | "### To get a dataframe - " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "brics.loc[['RU']]" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "brics.loc[['RU', 'IN']]" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "brics.loc[['RU', 'IN'], ['country', 'capital']]" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "## RECAP" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "### Square Brackets\n", 165 | "- column access : brics['country', 'capital']\n", 166 | "- Row access - only through slicing : brics[1:4]\n", 167 | "\n", 168 | "### loc \n", 169 | "- Row access : brics.loc[['RU', 'IN']]\n", 170 | "- column access : brics.loc[:, ['country', 'capital']]" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": {}, 176 | "source": [ 177 | "## iloc " 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": null, 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "brics.iloc[[1, 2], [0,1]]" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "## brics.loc[['RU', 'IN'], ['country', 'capital']] = brics.iloc[[1, 2], [0, 1]]" 194 | ] 195 | } 196 | ], 197 | "metadata": { 198 | "kernelspec": { 199 | "display_name": "Python 3", 200 | "language": "python", 201 | "name": "python3" 202 | }, 203 | "language_info": { 204 | "codemirror_mode": { 205 | "name": "ipython", 206 | "version": 3 207 | }, 208 | "file_extension": ".py", 209 | "mimetype": "text/x-python", 210 | "name": "python", 211 | "nbconvert_exporter": "python", 212 | "pygments_lexer": "ipython3", 213 | "version": "3.6.4" 214 | } 215 | }, 216 | "nbformat": 4, 217 | "nbformat_minor": 2 218 | } 219 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/.ipynb_checkpoints/Example_BRICS-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Example BRICS Countries" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import pandas as pd" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "brics = pd.read_csv('BRICS.csv', index_col = 0)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "brics" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "brics['country']" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "type(brics['country'])" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "brics[['country']]" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "type(brics[['country']])" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "brics[['country', 'capital']]" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "brics[1:4]" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "### Square brackets work, but it has limited functionality\n", 96 | "\n", 97 | "ideally it is similar to 2D NumPy arrays\n", 98 | "\n", 99 | "np_array[row, col]\n", 100 | "\n", 101 | "\n", 102 | "### loc and iloc\n", 103 | "\n", 104 | "- loc - workss for labels\n", 105 | "- iloc - works for positions" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "brics.loc['RU']" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "#### loc returns a row as pandas series object\n", 122 | "\n", 123 | "### To get a dataframe - " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "brics.loc[['RU']]" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "brics.loc[['RU', 'IN']]" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "brics.loc[['RU', 'IN'], ['country', 'capital']]" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "## RECAP" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "### Square Brackets\n", 165 | "- column access : brics['country', 'capital']\n", 166 | "- Row access - only through slicing : brics[1:4]\n", 167 | "\n", 168 | "### loc \n", 169 | "- Row access : brics.loc[['RU', 'IN']]\n", 170 | "- column access : brics.loc[:, ['country', 'capital']]" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": {}, 176 | "source": [ 177 | "## iloc " 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": null, 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "brics.iloc[[1, 2], [0,1]]" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "## brics.loc[['RU', 'IN'], ['country', 'capital']] = brics.iloc[[1, 2], [0, 1]]" 194 | ] 195 | } 196 | ], 197 | "metadata": { 198 | "kernelspec": { 199 | "display_name": "Python 3", 200 | "language": "python", 201 | "name": "python3" 202 | }, 203 | "language_info": { 204 | "codemirror_mode": { 205 | "name": "ipython", 206 | "version": 3 207 | }, 208 | "file_extension": ".py", 209 | "mimetype": "text/x-python", 210 | "name": "python", 211 | "nbconvert_exporter": "python", 212 | "pygments_lexer": "ipython3", 213 | "version": "3.6.4" 214 | } 215 | }, 216 | "nbformat": 4, 217 | "nbformat_minor": 2 218 | } 219 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/1. Variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Variables in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Variables in Python are not typed, which means they can literally store any value." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Here are some examples of Variables" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "a = 5\n", 31 | "type(a)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "b = 5.5\n", 41 | "type(b)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "### Strings in Python\n", 49 | "In python, anything between a single quote or a double quote is a string.\n", 50 | "e.g. 'Hello' is same as \"Hello\"" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "c = 'Hello'\n", 60 | "type(c)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "d = \"Hello\"\n", 70 | "type(d)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "### to check whether 'Hello' is same as \"Hello\"\n", 78 | "we can compare strings in python directly using equality operator (==)\n", 79 | "Unlike in c/c++ we generally use strcmp function, which returns 0 if strings are same" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "c == d" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "'I love Python' == \"I love Python\"" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "'Python' == 'python'" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "The above statement return false because python is a case sensitive language and 'P' is different from 'p'" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "### Boolean Data type in Python\n", 121 | "Python has bui;t in boolean values, True and False\n", 122 | "Note that C which returns 0 for false conditions and 1 for true conditions, but in python, a comparision or a condition always return True or False.\n", 123 | "\n", 124 | "Yet, just like c/c++, in python, 0 is considered a False value and any positive value is considered True." 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "x = True\n", 134 | "type(x)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "if 1:\n", 144 | " print('If condition evaluates to true, because 1 is considered True')\n", 145 | "else:\n", 146 | " print('This part never runs')" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "a == b" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "### Changing Value in variable\n", 163 | "If we change the value of a variable, it is now a new variable and older one is removed" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "a = 5\n", 173 | "print(type(a))\n", 174 | "print(a)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "a = 'Hello'\n", 184 | "print(type(a))\n", 185 | "print(a)" 186 | ] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "Python 3", 192 | "language": "python", 193 | "name": "python3" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 3 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython3", 205 | "version": "3.6.4" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 2 210 | } 211 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/.ipynb_checkpoints/Variables-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Variables in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Variables in Python are not typed, which means they can literally store any value." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Here are some examples of Variables" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "a = 5\n", 31 | "type(a)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "b = 5.5\n", 41 | "type(b)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "### Strings in Python\n", 49 | "In python, anything between a single quote or a double quote is a string.\n", 50 | "e.g. 'Hello' is same as \"Hello\"" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "c = 'Hello'\n", 60 | "type(c)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "d = \"Hello\"\n", 70 | "type(d)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "### to check whether 'Hello' is same as \"Hello\"\n", 78 | "we can compare strings in python directly using equality operator (==)\n", 79 | "Unlike in c/c++ we generally use strcmp function, which returns 0 if strings are same" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "c == d" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "'I love Python' == \"I love Python\"" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "'Python' == 'python'" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "The above statement return false because python is a case sensitive language and 'P' is different from 'p'" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "### Boolean Data type in Python\n", 121 | "Python has bui;t in boolean values, True and False\n", 122 | "Note that C which returns 0 for false conditions and 1 for true conditions, but in python, a comparision or a condition always return True or False.\n", 123 | "\n", 124 | "Yet, just like c/c++, in python, 0 is considered a False value and any positive value is considered True." 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "x = True\n", 134 | "type(x)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "if 1:\n", 144 | " print('If condition evaluates to true, because 1 is considered True')\n", 145 | "else:\n", 146 | " print('This part never runs')" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "a == b" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "### Changing Value in variable\n", 163 | "If we change the value of a variable, it is now a new variable and older one is removed" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "a = 5\n", 173 | "print(type(a))\n", 174 | "print(a)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "a = 'Hello'\n", 184 | "print(type(a))\n", 185 | "print(a)" 186 | ] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "Python 3", 192 | "language": "python", 193 | "name": "python3" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 3 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython3", 205 | "version": "3.6.4" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 2 210 | } 211 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/example.csv: -------------------------------------------------------------------------------- 1 | ,gdp_cap,life_exp,pop 2 | 0,974.5803384,43.828,31.889923 3 | 1,5937.029525999998,76.423,3.600523 4 | 2,6223.367465,72.301,33.333216 5 | 3,4797.231267,42.731,12.420476 6 | 4,12779.37964,75.32,40.301927 7 | 5,34435.367439999995,81.235,20.434176 8 | 6,36126.4927,79.829,8.199783 9 | 7,29796.04834,75.635,0.708573 10 | 8,1391.253792,64.062,150.448339 11 | 9,33692.60508,79.441,10.392226 12 | 10,1441.284873,56.728,8.078314 13 | 11,3822.137084,65.554,9.119152 14 | 12,7446.298803,74.852,4.552198 15 | 13,12569.85177,50.728,1.639131 16 | 14,9065.800825,72.39,190.010647 17 | 15,10680.79282,73.005,7.322858 18 | 16,1217.032994,52.295,14.326203 19 | 17,430.0706916,49.58,8.390505 20 | 18,1713.778686,59.723,14.131858 21 | 19,2042.09524,50.43,17.696293 22 | 20,36319.23501,80.653,33.390141 23 | 21,706.016537,44.74100000000001,4.369038 24 | 22,1704.063724,50.651,10.238807 25 | 23,13171.63885,78.553,16.284741 26 | 24,4959.114854,72.961,1318.683096 27 | 25,7006.580419,72.889,44.22755 28 | 26,986.1478792,65.152,0.71096 29 | 27,277.5518587,46.462,64.606759 30 | 28,3632.557798,55.322,3.80061 31 | 29,9645.06142,78.782,4.133884 32 | 30,1544.750112,48.328,18.013409 33 | 31,14619.222719999998,75.748,4.493312 34 | 32,8948.102923,78.273,11.416987 35 | 33,22833.30851,76.486,10.228744 36 | 34,35278.41874,78.332,5.46812 37 | 35,2082.4815670000007,54.791,0.496374 38 | 36,6025.3747520000015,72.235,9.319622 39 | 37,6873.262326000001,74.994,13.75568 40 | 38,5581.180998,71.33800000000002,80.264543 41 | 39,5728.353514,71.878,6.939688 42 | 40,12154.08975,51.57899999999999,0.551201 43 | 41,641.3695236000002,58.04,4.906585 44 | 42,690.8055759,52.947,76.511887 45 | 43,33207.0844,79.313,5.23846 46 | 44,30470.0167,80.657,61.083916 47 | 45,13206.48452,56.735,1.454867 48 | 46,752.7497265,59.448,1.688359 49 | 47,32170.37442,79.406,82.400996 50 | 48,1327.60891,60.022,22.873338 51 | 49,27538.41188,79.483,10.70629 52 | 50,5186.050003,70.259,12.572928 53 | 51,942.6542111,56.007,9.947814 54 | 52,579.2317429999998,46.38800000000001,1.472041 55 | 53,1201.637154,60.916,8.502814 56 | 54,3548.3308460000007,70.19800000000001,7.483763 57 | 55,39724.97867,82.208,6.980412 58 | 56,18008.94444,73.33800000000002,9.956108 59 | 57,36180.78919,81.757,0.301931 60 | 58,2452.210407,64.69800000000001,1110.396331 61 | 59,3540.651564,70.65,223.547 62 | 60,11605.71449,70.964,69.45357 63 | 61,4471.061906,59.545,27.499638 64 | 62,40675.99635,78.885,4.109086 65 | 63,25523.2771,80.745,6.426679 66 | 64,28569.7197,80.546,58.147733 67 | 65,7320.8802620000015,72.567,2.780132 68 | 66,31656.06806,82.603,127.467972 69 | 67,4519.461171,72.535,6.053193 70 | 68,1463.249282,54.11,35.610177 71 | 69,1593.06548,67.297,23.301725 72 | 70,23348.139730000006,78.623,49.04479 73 | 71,47306.98978,77.58800000000002,2.505559 74 | 72,10461.05868,71.993,3.921278 75 | 73,1569.331442,42.592,2.012649 76 | 74,414.5073415,45.678,3.193942 77 | 75,12057.49928,73.952,6.036914 78 | 76,1044.770126,59.44300000000001,19.167654 79 | 77,759.3499101,48.303,13.327079 80 | 78,12451.6558,74.241,24.821286 81 | 79,1042.581557,54.467,12.031795 82 | 80,1803.151496,64.164,3.270065 83 | 81,10956.99112,72.801,1.250882 84 | 82,11977.57496,76.195,108.700891 85 | 83,3095.7722710000007,66.803,2.874127 86 | 84,9253.896111,74.543,0.684736 87 | 85,3820.17523,71.164,33.757175 88 | 86,823.6856205,42.082,19.951656 89 | 87,944.0,62.069,47.76198 90 | 88,4811.060429,52.90600000000001,2.05508 91 | 89,1091.359778,63.785,28.90179 92 | 90,36797.93332,79.762,16.570613 93 | 91,25185.00911,80.204,4.115771 94 | 92,2749.320965,72.899,5.675356 95 | 93,619.6768923999998,56.867,12.894865 96 | 94,2013.977305,46.859,135.031164 97 | 95,49357.19017,80.196,4.627926 98 | 96,22316.19287,75.64,3.204897 99 | 97,2605.94758,65.483,169.270617 100 | 98,9809.185636,75.53699999999998,3.242173 101 | 99,4172.838464,71.752,6.667147 102 | 100,7408.905561,71.421,28.674757 103 | 101,3190.481016,71.688,91.077287 104 | 102,15389.924680000002,75.563,38.518241 105 | 103,20509.64777,78.098,10.642836 106 | 104,19328.70901,78.74600000000002,3.942491 107 | 105,7670.122558,76.442,0.798094 108 | 106,10808.47561,72.476,22.276056 109 | 107,863.0884639000002,46.242,8.860588 110 | 108,1598.435089,65.528,0.199579 111 | 109,21654.83194,72.777,27.601038 112 | 110,1712.472136,63.062,12.267493 113 | 111,9786.534714,74.002,10.150265 114 | 112,862.5407561000002,42.56800000000001,6.144562 115 | 113,47143.17964,79.972,4.553009 116 | 114,18678.31435,74.663,5.447502 117 | 115,25768.25759,77.926,2.009245 118 | 116,926.1410683,48.159,9.118773 119 | 117,9269.657808,49.339,43.997828 120 | 118,28821.0637,80.941,40.448191 121 | 119,3970.095407,72.396,20.378239 122 | 120,2602.394995,58.556,42.292929 123 | 121,4513.480643,39.613,1.133066 124 | 122,33859.74835,80.884,9.031088 125 | 123,37506.41907,81.70100000000002,7.554661 126 | 124,4184.548089,74.143,19.314747 127 | 125,28718.27684,78.4,23.174294 128 | 126,1107.482182,52.517,38.13964 129 | 127,7458.396326999998,70.616,65.068149 130 | 128,882.9699437999999,58.42,5.701579 131 | 129,18008.50924,69.819,1.056608 132 | 130,7092.923025,73.923,10.276158 133 | 131,8458.276384,71.777,71.158647 134 | 132,1056.380121,51.542,29.170398 135 | 133,33203.26128,79.425,60.776238 136 | 134,42951.65309,78.242,301.139947 137 | 135,10611.46299,76.384,3.447496 138 | 136,11415.80569,73.747,26.084662 139 | 137,2441.576404,74.249,85.262356 140 | 138,3025.349798,73.422,4.018332 141 | 139,2280.769906,62.698,22.211743 142 | 140,1271.211593,42.38399999999999,11.746035 143 | 141,469.70929810000007,43.487,12.311143 144 | -------------------------------------------------------------------------------- /Day 1/3. List Tuples and Dictionaries/4. List_comprehensions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# List Comprehensions" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "# Creating an empty list\n", 25 | "a = []\n", 26 | " \n", 27 | "for x in range(20):\n", 28 | " a.append(x)\n", 29 | " \n", 30 | "print(a)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 4, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "# Using list comprehension\n", 48 | "\n", 49 | "b = [x for x in range(20)]\n", 50 | "print(b)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "raw", 55 | "metadata": {}, 56 | "source": [ 57 | "List comprehensions provide a concise way to create lists. \n", 58 | "\n", 59 | "It consists of brackets containing an expression followed by a for clause, then\n", 60 | "zero or more for or if clauses. The expressions can be anything, meaning you can\n", 61 | "put in all kinds of objects in lists.\n", 62 | "\n", 63 | "The result will be a new list resulting from evaluating the expression in the\n", 64 | "context of the for and if clauses which follow it. \n", 65 | "\n", 66 | "The list comprehension always returns a result list. " 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 5, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "[16, 17, 18, 19]\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "c = [i for i in range(20) if i > 15]\n", 84 | "print(c)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 6, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "[256, 289, 324, 361]\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "c = [i**2 for i in range(20) if i > 15]\n", 102 | "print(c)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 8, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "[512, 578, 648, 722]\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "doubles = [i*2 for i in c]\n", 120 | "print(doubles)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### Suppose you have a list of strings and you want to create a list with first letters in the name" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 11, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "['B', 'M', 'S', 'K']\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "names = ['Bob', 'Marrie', 'Susan', 'Kate']\n", 145 | "\n", 146 | "first_letters = [name[0] for name in names]\n", 147 | "print(first_letters)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 12, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "name": "stdout", 157 | "output_type": "stream", 158 | "text": [ 159 | "[100, 90, 80, 110, 100, 90, 120, 110, 100]\n" 160 | ] 161 | } 162 | ], 163 | "source": [ 164 | "a = [x + y for x in [10, 20, 30] for y in [90, 80, 70]]\n", 165 | "print(a)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 14, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "[10, 20, 30, 90, 80, 70]\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "a = [10, 20, 30] + [90, 80, 70]\n", 183 | "print(a)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 15, 189 | "metadata": { 190 | "scrolled": true 191 | }, 192 | "outputs": [ 193 | { 194 | "name": "stdout", 195 | "output_type": "stream", 196 | "text": [ 197 | "[10, 20, 30, 10, 20, 30]\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "a = [10, 20, 30] * 2\n", 203 | "print(a)" 204 | ] 205 | } 206 | ], 207 | "metadata": { 208 | "kernelspec": { 209 | "display_name": "Python 3", 210 | "language": "python", 211 | "name": "python3" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.6.4" 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 2 228 | } 229 | -------------------------------------------------------------------------------- /Day 1/3. List Tuples and Dictionaries/.ipynb_checkpoints/List_comprehensions-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# List Comprehensions" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "# Creating an empty list\n", 25 | "a = []\n", 26 | " \n", 27 | "for x in range(20):\n", 28 | " a.append(x)\n", 29 | " \n", 30 | "print(a)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 4, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "# Using list comprehension\n", 48 | "\n", 49 | "b = [x for x in range(20)]\n", 50 | "print(b)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "raw", 55 | "metadata": {}, 56 | "source": [ 57 | "List comprehensions provide a concise way to create lists. \n", 58 | "\n", 59 | "It consists of brackets containing an expression followed by a for clause, then\n", 60 | "zero or more for or if clauses. The expressions can be anything, meaning you can\n", 61 | "put in all kinds of objects in lists.\n", 62 | "\n", 63 | "The result will be a new list resulting from evaluating the expression in the\n", 64 | "context of the for and if clauses which follow it. \n", 65 | "\n", 66 | "The list comprehension always returns a result list. " 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 5, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "[16, 17, 18, 19]\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "c = [i for i in range(20) if i > 15]\n", 84 | "print(c)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 6, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "[256, 289, 324, 361]\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "c = [i**2 for i in range(20) if i > 15]\n", 102 | "print(c)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 8, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "[512, 578, 648, 722]\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "doubles = [i*2 for i in c]\n", 120 | "print(doubles)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### Suppose you have a list of strings and you want to create a list with first letters in the name" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 11, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "['B', 'M', 'S', 'K']\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "names = ['Bob', 'Marrie', 'Susan', 'Kate']\n", 145 | "\n", 146 | "first_letters = [name[0] for name in names]\n", 147 | "print(first_letters)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 12, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "name": "stdout", 157 | "output_type": "stream", 158 | "text": [ 159 | "[100, 90, 80, 110, 100, 90, 120, 110, 100]\n" 160 | ] 161 | } 162 | ], 163 | "source": [ 164 | "a = [x + y for x in [10, 20, 30] for y in [90, 80, 70]]\n", 165 | "print(a)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 14, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "[10, 20, 30, 90, 80, 70]\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "a = [10, 20, 30] + [90, 80, 70]\n", 183 | "print(a)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 15, 189 | "metadata": { 190 | "scrolled": true 191 | }, 192 | "outputs": [ 193 | { 194 | "name": "stdout", 195 | "output_type": "stream", 196 | "text": [ 197 | "[10, 20, 30, 10, 20, 30]\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "a = [10, 20, 30] * 2\n", 203 | "print(a)" 204 | ] 205 | } 206 | ], 207 | "metadata": { 208 | "kernelspec": { 209 | "display_name": "Python 3", 210 | "language": "python", 211 | "name": "python3" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.6.4" 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 2 228 | } 229 | -------------------------------------------------------------------------------- /Day 1/3. List Tuples and Dictionaries/3. Tuples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuples" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "A Tuple is a collection of Python objects separated by commas. In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "a = (1, 2, 3)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "(1, 2, 3)\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "print(a)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "tuple" 52 | ] 53 | }, 54 | "execution_count": 3, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "type(a)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "print(type(a))" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 5, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "data": { 87 | "text/plain": [ 88 | "3" 89 | ] 90 | }, 91 | "execution_count": 5, 92 | "metadata": {}, 93 | "output_type": "execute_result" 94 | } 95 | ], 96 | "source": [ 97 | "a[2]" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "## How to break a tuple into individual values" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 6, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "a, b, c = (1, 2, 3)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "1\n", 126 | "2\n", 127 | "3\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "print(a)\n", 133 | "print(b)\n", 134 | "print(c)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 8, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "\n", 147 | "\n", 148 | "\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "print(type(a))\n", 154 | "print(type(b))\n", 155 | "print(type(c))" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "### Functions that return multiple values are returned in tuples" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 9, 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "def multi():\n", 172 | " return 2, 3, 4" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 10, 178 | "metadata": { 179 | "scrolled": true 180 | }, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "a = multi()\n", 192 | "print(type(a))" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "### Tuples are immutable" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 11, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "a = (1, 2, 3)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 12, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "ename": "TypeError", 218 | "evalue": "'tuple' object does not support item assignment", 219 | "output_type": "error", 220 | "traceback": [ 221 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 222 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 223 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 224 | "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "a[1] = 5" 230 | ] 231 | } 232 | ], 233 | "metadata": { 234 | "kernelspec": { 235 | "display_name": "Python 3", 236 | "language": "python", 237 | "name": "python3" 238 | }, 239 | "language_info": { 240 | "codemirror_mode": { 241 | "name": "ipython", 242 | "version": 3 243 | }, 244 | "file_extension": ".py", 245 | "mimetype": "text/x-python", 246 | "name": "python", 247 | "nbconvert_exporter": "python", 248 | "pygments_lexer": "ipython3", 249 | "version": "3.6.4" 250 | } 251 | }, 252 | "nbformat": 4, 253 | "nbformat_minor": 2 254 | } 255 | -------------------------------------------------------------------------------- /Day 1/3. List Tuples and Dictionaries/.ipynb_checkpoints/Tuples-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuples" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "A Tuple is a collection of Python objects separated by commas. In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "a = (1, 2, 3)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "(1, 2, 3)\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "print(a)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "tuple" 52 | ] 53 | }, 54 | "execution_count": 3, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "type(a)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "print(type(a))" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 5, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "data": { 87 | "text/plain": [ 88 | "3" 89 | ] 90 | }, 91 | "execution_count": 5, 92 | "metadata": {}, 93 | "output_type": "execute_result" 94 | } 95 | ], 96 | "source": [ 97 | "a[2]" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "## How to break a tuple into individual values" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 6, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "a, b, c = (1, 2, 3)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "1\n", 126 | "2\n", 127 | "3\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "print(a)\n", 133 | "print(b)\n", 134 | "print(c)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 8, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "\n", 147 | "\n", 148 | "\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "print(type(a))\n", 154 | "print(type(b))\n", 155 | "print(type(c))" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "### Functions that return multiple values are returned in tuples" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 9, 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "def multi():\n", 172 | " return 2, 3, 4" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 10, 178 | "metadata": { 179 | "scrolled": true 180 | }, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "a = multi()\n", 192 | "print(type(a))" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "### Tuples are immutable" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 11, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "a = (1, 2, 3)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 12, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "ename": "TypeError", 218 | "evalue": "'tuple' object does not support item assignment", 219 | "output_type": "error", 220 | "traceback": [ 221 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 222 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 223 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 224 | "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "a[1] = 5" 230 | ] 231 | } 232 | ], 233 | "metadata": { 234 | "kernelspec": { 235 | "display_name": "Python 3", 236 | "language": "python", 237 | "name": "python3" 238 | }, 239 | "language_info": { 240 | "codemirror_mode": { 241 | "name": "ipython", 242 | "version": 3 243 | }, 244 | "file_extension": ".py", 245 | "mimetype": "text/x-python", 246 | "name": "python", 247 | "nbconvert_exporter": "python", 248 | "pygments_lexer": "ipython3", 249 | "version": "3.6.4" 250 | } 251 | }, 252 | "nbformat": 4, 253 | "nbformat_minor": 2 254 | } 255 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/5. Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Functions in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### The print function" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "value of a is: 4 and that of b is: 5\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "a = 4\n", 32 | "b = 5\n", 33 | "print('value of a is: ', a, 'and that of b is: ', b)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 4, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "4 5\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "print(a, b)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 3, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "4\n", 63 | "5\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "print(a, b, sep = '\\n')" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 6, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "4 5\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "print(a, end = ' ')\n", 86 | "print(b)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 7, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "HelloWorld\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "print('Hello' + 'World')" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "## Creating your own functions\n", 111 | "def keyword" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 9, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "Hello\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "def foo():\n", 129 | " print('Hello')\n", 130 | "\n", 131 | "foo()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 10, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Hello\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "foo()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 12, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "Hello Naveen\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "def greet(name):\n", 166 | " print('Hello', name)\n", 167 | "\n", 168 | "greet('Naveen')" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "Returning values from functions" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 13, 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [ 184 | "def prime(num):\n", 185 | " for x in range (num // 2):\n", 186 | " if num % 2 == 0:\n", 187 | " return False\n", 188 | " \n", 189 | " return True" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 14, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "True" 201 | ] 202 | }, 203 | "execution_count": 14, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "prime(7)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 15, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "data": { 219 | "text/plain": [ 220 | "False" 221 | ] 222 | }, 223 | "execution_count": 15, 224 | "metadata": {}, 225 | "output_type": "execute_result" 226 | } 227 | ], 228 | "source": [ 229 | "prime(4)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "## Returning multiple Values-" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 16, 242 | "metadata": {}, 243 | "outputs": [], 244 | "source": [ 245 | "def multi():\n", 246 | " return 2,3,4" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 17, 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "name": "stdout", 256 | "output_type": "stream", 257 | "text": [ 258 | "(2, 3, 4)\n" 259 | ] 260 | } 261 | ], 262 | "source": [ 263 | "print(multi())" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "metadata": {}, 269 | "source": [ 270 | "Above function returns a tuple" 271 | ] 272 | } 273 | ], 274 | "metadata": { 275 | "kernelspec": { 276 | "display_name": "Python 3", 277 | "language": "python", 278 | "name": "python3" 279 | }, 280 | "language_info": { 281 | "codemirror_mode": { 282 | "name": "ipython", 283 | "version": 3 284 | }, 285 | "file_extension": ".py", 286 | "mimetype": "text/x-python", 287 | "name": "python", 288 | "nbconvert_exporter": "python", 289 | "pygments_lexer": "ipython3", 290 | "version": "3.6.4" 291 | } 292 | }, 293 | "nbformat": 4, 294 | "nbformat_minor": 2 295 | } 296 | -------------------------------------------------------------------------------- /Day 1/1. Basic Programming Constructs/.ipynb_checkpoints/Functions-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Functions in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### The print function" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "value of a is: 4 and that of b is: 5\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "a = 4\n", 32 | "b = 5\n", 33 | "print('value of a is: ', a, 'and that of b is: ', b)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 4, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "4 5\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "print(a, b)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 3, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "4\n", 63 | "5\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "print(a, b, sep = '\\n')" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 6, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "4 5\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "print(a, end = ' ')\n", 86 | "print(b)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 7, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "HelloWorld\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "print('Hello' + 'World')" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "## Creating your own functions\n", 111 | "def keyword" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 9, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "Hello\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "def foo():\n", 129 | " print('Hello')\n", 130 | "\n", 131 | "foo()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 10, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Hello\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "foo()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 12, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "Hello Naveen\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "def greet(name):\n", 166 | " print('Hello', name)\n", 167 | "\n", 168 | "greet('Naveen')" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "Returning values from functions" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 13, 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [ 184 | "def prime(num):\n", 185 | " for x in range (num // 2):\n", 186 | " if num % 2 == 0:\n", 187 | " return False\n", 188 | " \n", 189 | " return True" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 14, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "True" 201 | ] 202 | }, 203 | "execution_count": 14, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "prime(7)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 15, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "data": { 219 | "text/plain": [ 220 | "False" 221 | ] 222 | }, 223 | "execution_count": 15, 224 | "metadata": {}, 225 | "output_type": "execute_result" 226 | } 227 | ], 228 | "source": [ 229 | "prime(4)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "## Returning multiple Values-" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 16, 242 | "metadata": {}, 243 | "outputs": [], 244 | "source": [ 245 | "def multi():\n", 246 | " return 2,3,4" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 17, 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "name": "stdout", 256 | "output_type": "stream", 257 | "text": [ 258 | "(2, 3, 4)\n" 259 | ] 260 | } 261 | ], 262 | "source": [ 263 | "print(multi())" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "metadata": {}, 269 | "source": [ 270 | "Above function returns a tuple" 271 | ] 272 | } 273 | ], 274 | "metadata": { 275 | "kernelspec": { 276 | "display_name": "Python 3", 277 | "language": "python", 278 | "name": "python3" 279 | }, 280 | "language_info": { 281 | "codemirror_mode": { 282 | "name": "ipython", 283 | "version": 3 284 | }, 285 | "file_extension": ".py", 286 | "mimetype": "text/x-python", 287 | "name": "python", 288 | "nbconvert_exporter": "python", 289 | "pygments_lexer": "ipython3", 290 | "version": "3.6.4" 291 | } 292 | }, 293 | "nbformat": 4, 294 | "nbformat_minor": 2 295 | } 296 | -------------------------------------------------------------------------------- /Day 2/3. Data Visualization Matplotlib/Raw Data.txt: -------------------------------------------------------------------------------- 1 | data for customization.ipynb 2 | year 3 | [1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100] 4 | 5 | pop 6 | [2.53, 2.57, 2.62, 2.67, 2.71, 2.76, 2.81, 2.86, 2.92, 2.97, 3.03, 3.08, 3.14, 3.2, 3.26, 3.33, 3.4, 3.47, 3.54, 3.62, 3.69, 3.77, 3.84, 3.92, 4.0, 4.07, 4.15, 4.22, 4.3, 4.37, 4.45, 4.53, 4.61, 4.69, 4.78, 4.86, 4.95, 5.05, 5.14, 5.23, 5.32, 5.41, 5.49, 5.58, 5.66, 5.74, 5.82, 5.9, 5.98, 6.05, 6.13, 6.2, 6.28, 6.36, 6.44, 6.51, 6.59, 6.67, 6.75, 6.83, 6.92, 7.0, 7.08, 7.16, 7.24, 7.32, 7.4, 7.48, 7.56, 7.64, 7.72, 7.79, 7.87, 7.94, 8.01, 8.08, 8.15, 8.22, 8.29, 8.36, 8.42, 8.49, 8.56, 8.62, 8.68, 8.74, 8.8, 8.86, 8.92, 8.98, 9.04, 9.09, 9.15, 9.2, 9.26, 9.31, 9.36, 9.41, 9.46, 9.5, 9.55, 9.6, 9.64, 9.68, 9.73, 9.77, 9.81, 9.85, 9.88, 9.92, 9.96, 9.99, 10.03, 10.06, 10.09, 10.13, 10.16, 10.19, 10.22, 10.25, 10.28, 10.31, 10.33, 10.36, 10.38, 10.41, 10.43, 10.46, 10.48, 10.5, 10.52, 10.55, 10.57, 10.59, 10.61, 10.63, 10.65, 10.66, 10.68, 10.7, 10.72, 10.73, 10.75, 10.77, 10.78, 10.79, 10.81, 10.82, 10.83, 10.84, 10.85] 7 | 8 | 9 | Data for Example.ipynb 10 | 11 | gdp_cap 12 | [974.5803384, 5937.029525999998, 6223.367465, 4797.231267, 12779.37964, 34435.367439999995, 36126.4927, 29796.04834, 1391.253792, 33692.60508, 1441.284873, 3822.137084, 7446.298803, 12569.85177, 9065.800825, 10680.79282, 1217.032994, 430.0706916, 1713.778686, 2042.09524, 36319.23501, 706.016537, 1704.063724, 13171.63885, 4959.114854, 7006.580419, 986.1478792, 277.5518587, 3632.557798, 9645.06142, 1544.750112, 14619.222719999998, 8948.102923, 22833.30851, 35278.41874, 2082.4815670000007, 6025.3747520000015, 6873.262326000001, 5581.180998, 5728.353514, 12154.08975, 641.3695236000002, 690.8055759, 33207.0844, 30470.0167, 13206.48452, 752.7497265, 32170.37442, 1327.60891, 27538.41188, 5186.050003, 942.6542111, 579.2317429999998, 1201.637154, 3548.3308460000007, 39724.97867, 18008.94444, 36180.78919, 2452.210407, 3540.651564, 11605.71449, 4471.061906, 40675.99635, 25523.2771, 28569.7197, 7320.8802620000015, 31656.06806, 4519.461171, 1463.249282, 1593.06548, 23348.139730000006, 47306.98978, 10461.05868, 1569.331442, 414.5073415, 12057.49928, 1044.770126, 759.3499101, 12451.6558, 1042.581557, 1803.151496, 10956.99112, 11977.57496, 3095.7722710000007, 9253.896111, 3820.17523, 823.6856205, 944.0, 4811.060429, 1091.359778, 36797.93332, 25185.00911, 2749.320965, 619.6768923999998, 2013.977305, 49357.19017, 22316.19287, 2605.94758, 9809.185636, 4172.838464, 7408.905561, 3190.481016, 15389.924680000002, 20509.64777, 19328.70901, 7670.122558, 10808.47561, 863.0884639000002, 1598.435089, 21654.83194, 1712.472136, 9786.534714, 862.5407561000002, 47143.17964, 18678.31435, 25768.25759, 926.1410683, 9269.657808, 28821.0637, 3970.095407, 2602.394995, 4513.480643, 33859.74835, 37506.41907, 4184.548089, 28718.27684, 1107.482182, 7458.396326999998, 882.9699437999999, 18008.50924, 7092.923025, 8458.276384, 1056.380121, 33203.26128, 42951.65309, 10611.46299, 11415.80569, 2441.576404, 3025.349798, 2280.769906, 1271.211593, 469.70929810000007] 13 | 14 | life_exp 15 | [43.828, 76.423, 72.301, 42.731, 75.32, 81.235, 79.829, 75.635, 64.062, 79.441, 56.728, 65.554, 74.852, 50.728, 72.39, 73.005, 52.295, 49.58, 59.723, 50.43, 80.653, 44.74100000000001, 50.651, 78.553, 72.961, 72.889, 65.152, 46.462, 55.322, 78.782, 48.328, 75.748, 78.273, 76.486, 78.332, 54.791, 72.235, 74.994, 71.33800000000002, 71.878, 51.57899999999999, 58.04, 52.947, 79.313, 80.657, 56.735, 59.448, 79.406, 60.022, 79.483, 70.259, 56.007, 46.38800000000001, 60.916, 70.19800000000001, 82.208, 73.33800000000002, 81.757, 64.69800000000001, 70.65, 70.964, 59.545, 78.885, 80.745, 80.546, 72.567, 82.603, 72.535, 54.11, 67.297, 78.623, 77.58800000000002, 71.993, 42.592, 45.678, 73.952, 59.44300000000001, 48.303, 74.241, 54.467, 64.164, 72.801, 76.195, 66.803, 74.543, 71.164, 42.082, 62.069, 52.90600000000001, 63.785, 79.762, 80.204, 72.899, 56.867, 46.859, 80.196, 75.64, 65.483, 75.53699999999998, 71.752, 71.421, 71.688, 75.563, 78.098, 78.74600000000002, 76.442, 72.476, 46.242, 65.528, 72.777, 63.062, 74.002, 42.56800000000001, 79.972, 74.663, 77.926, 48.159, 49.339, 80.941, 72.396, 58.556, 39.613, 80.884, 81.70100000000002, 74.143, 78.4, 52.517, 70.616, 58.42, 69.819, 73.923, 71.777, 51.542, 79.425, 78.242, 76.384, 73.747, 74.249, 73.422, 62.698, 42.38399999999999, 43.487] 16 | 17 | pop 18 | [31.889923, 3.600523, 33.333216, 12.420476, 40.301927, 20.434176, 8.199783, 0.708573, 150.448339, 10.392226, 8.078314, 9.119152, 4.552198, 1.639131, 190.010647, 7.322858, 14.326203, 8.390505, 14.131858, 17.696293, 33.390141, 4.369038, 10.238807, 16.284741, 1318.683096, 44.22755, 0.71096, 64.606759, 3.80061, 4.133884, 18.013409, 4.493312, 11.416987, 10.228744, 5.46812, 0.496374, 9.319622, 13.75568, 80.264543, 6.939688, 0.551201, 4.906585, 76.511887, 5.23846, 61.083916, 1.454867, 1.688359, 82.400996, 22.873338, 10.70629, 12.572928, 9.947814, 1.472041, 8.502814, 7.483763, 6.980412, 9.956108, 0.301931, 1110.396331, 223.547, 69.45357, 27.499638, 4.109086, 6.426679, 58.147733, 2.780132, 127.467972, 6.053193, 35.610177, 23.301725, 49.04479, 2.505559, 3.921278, 2.012649, 3.193942, 6.036914, 19.167654, 13.327079, 24.821286, 12.031795, 3.270065, 1.250882, 108.700891, 2.874127, 0.684736, 33.757175, 19.951656, 47.76198, 2.05508, 28.90179, 16.570613, 4.115771, 5.675356, 12.894865, 135.031164, 4.627926, 3.204897, 169.270617, 3.242173, 6.667147, 28.674757, 91.077287, 38.518241, 10.642836, 3.942491, 0.798094, 22.276056, 8.860588, 0.199579, 27.601038, 12.267493, 10.150265, 6.144562, 4.553009, 5.447502, 2.009245, 9.118773, 43.997828, 40.448191, 20.378239, 42.292929, 1.133066, 9.031088, 7.554661, 19.314747, 23.174294, 38.13964, 65.068149, 5.701579, 1.056608, 10.276158, 71.158647, 29.170398, 60.776238, 301.139947, 3.447496, 26.084662, 85.262356, 4.018332, 22.211743, 11.746035, 12.311143] 19 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/3. Files.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Files in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Flat Files - a file having no internal hierarchy.\n", 15 | "\n", 16 | "e.g - text file, csv file\n", 17 | "\n", 18 | "Modes of file- \n", 19 | "\n", 20 | "Read Mode ('r') - File opened in read mode can not be edited. Only works if a file already exists.\n", 21 | "\n", 22 | "Write Mode ('w') - File opened in write mode can be edited but it completely clears the content in the file. It creates a new file if it don't already exist\n", 23 | "\n", 24 | "Append Mode ('a') - File opened in append mode enables to edit file, but it do not clear the file.\n", 25 | "\n", 26 | "r+ Mode - Opens for read and write, pointer at begining of file, doen't clear the file\n", 27 | "\n", 28 | "w+ Mode - Opens file in read and write and clears the content of file\n", 29 | "\n", 30 | "a+ Mode - Opens file in read and write mode and put the pointer to the end of the file\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 16, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "f = open('myfile.txt', 'w')\n", 48 | "print(type(f))\n", 49 | "\n", 50 | "f.write('Hello World')\n", 51 | "f.close()" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 17, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Hello World\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "file = open('myfile.txt', 'r')\n", 69 | "\n", 70 | "print(file.read())\n", 71 | "file.close()" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 18, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "file = open('myfile.txt', 'a')\n", 81 | "\n", 82 | "file.write('\\nSimple is better than complex')\n", 83 | "file.write('\\nComplex is better than complicated')\n", 84 | "\n", 85 | "file.close()" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "## Do we need close() all the time?" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 19, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "Hello World\n", 105 | "Simple is better than complex\n", 106 | "Complex is better than complicated" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "with open('myfile.txt', 'r') as file:\n", 112 | " for line in file:\n", 113 | " print(line, end = '')" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 21, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "True" 125 | ] 126 | }, 127 | "execution_count": 21, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "file.closed" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 22, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "'myfile.txt'" 145 | ] 146 | }, 147 | "execution_count": 22, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "file.name" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 23, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "data": { 163 | "text/plain": [ 164 | "'r'" 165 | ] 166 | }, 167 | "execution_count": 23, 168 | "metadata": {}, 169 | "output_type": "execute_result" 170 | } 171 | ], 172 | "source": [ 173 | "file.mode" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 33, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "Hello World\n", 186 | "Simple is better than complex\n", 187 | "Complex is better than complicated" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "with open('myfile.txt', 'r') as file:\n", 193 | " for line in file:\n", 194 | " print(line, end = '')" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 40, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "0\n", 207 | "Hello World\n", 208 | "Simple is better than complex\n", 209 | "Complex is better than complicated\n", 210 | "78\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "file = open('myfile.txt', 'r')\n", 216 | "print(file.tell())\n", 217 | "\n", 218 | "for line in file:\n", 219 | " print(line, end = '')\n", 220 | "\n", 221 | "print()\n", 222 | "print(file.tell())\n" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 37, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "print(file.read())" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 38, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "name": "stdout", 249 | "output_type": "stream", 250 | "text": [ 251 | "Hello World\n", 252 | "Simple is better than complex\n", 253 | "Complex is better than complicated\n" 254 | ] 255 | } 256 | ], 257 | "source": [ 258 | "file.seek(0)\n", 259 | "print(file.read())" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 41, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "False" 271 | ] 272 | }, 273 | "execution_count": 41, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "file.closed" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 42, 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [ 288 | "file.close()" 289 | ] 290 | } 291 | ], 292 | "metadata": { 293 | "kernelspec": { 294 | "display_name": "Python 3", 295 | "language": "python", 296 | "name": "python3" 297 | }, 298 | "language_info": { 299 | "codemirror_mode": { 300 | "name": "ipython", 301 | "version": 3 302 | }, 303 | "file_extension": ".py", 304 | "mimetype": "text/x-python", 305 | "name": "python", 306 | "nbconvert_exporter": "python", 307 | "pygments_lexer": "ipython3", 308 | "version": "3.6.4" 309 | } 310 | }, 311 | "nbformat": 4, 312 | "nbformat_minor": 2 313 | } 314 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/1. pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Pandas in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. It is free software released under the three-clause BSD license.\n", 15 | "\n", 16 | "\n", 17 | "2D NumPy array? - Similar data type\n", 18 | "\n", 19 | "Pandas is a high level data manipulation tool, developed bt Wes McKinney\n", 20 | "\n", 21 | "Pandas is built on NumPy package" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import pandas as pd" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "### Creating DataFrames" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "#### From Lists" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "df = pd.DataFrame([['Bob', 55],\n", 54 | " ['Vien', 52]])" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "type(df)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "print(df)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "#### From NumPy arrays" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "import numpy as np\n", 89 | "\n", 90 | "arr = np.arange(100).reshape(10,10)\n", 91 | "df = pd.DataFrame(arr)\n", 92 | "df" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "df = pd.read_csv('Book1.csv')" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "df" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "## Indexing in DataFrame" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "df['Revenue']" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "df[['Revenue','profit']]" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "### Methods and Attributes in DataFrame" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "Max and Min" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "df['Revenue'].max()" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "df['Revenue'].min()" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "Describing the dataframe" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "df.describe()" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "print(df.columns)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "df.shape" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [ 210 | "df.size" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": { 217 | "scrolled": true 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "df.values" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "df.index = ['ex1', 'ex2', 'ex3']\n", 231 | "df" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "#### Slicing DataFrame using comparision operator" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "df[df['Revenue']>3000]" 248 | ] 249 | }, 250 | { 251 | "cell_type": "markdown", 252 | "metadata": {}, 253 | "source": [ 254 | "### Converting DataFrame to NumPy ndarray" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": null, 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "df.as_matrix()" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "metadata": {}, 269 | "source": [ 270 | "## Importing csv in customized format" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "metadata": {}, 277 | "outputs": [], 278 | "source": [ 279 | "iris_data = pd.read_csv('iris.csv')" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [ 288 | "print(iris_data.head())" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | "iris_data = pd.read_csv('iris.csv', skiprows = 1, usecols = [0, 1, 2, 3], \n", 298 | " names = ['Sepal-Length', 'Spepal-Width', 'Petal-Length', 'Petal-Widht'])" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": null, 304 | "metadata": {}, 305 | "outputs": [], 306 | "source": [ 307 | "print(iris_data.head())" 308 | ] 309 | } 310 | ], 311 | "metadata": { 312 | "kernelspec": { 313 | "display_name": "Python 3", 314 | "language": "python", 315 | "name": "python3" 316 | }, 317 | "language_info": { 318 | "codemirror_mode": { 319 | "name": "ipython", 320 | "version": 3 321 | }, 322 | "file_extension": ".py", 323 | "mimetype": "text/x-python", 324 | "name": "python", 325 | "nbconvert_exporter": "python", 326 | "pygments_lexer": "ipython3", 327 | "version": "3.6.4" 328 | } 329 | }, 330 | "nbformat": 4, 331 | "nbformat_minor": 2 332 | } 333 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/.ipynb_checkpoints/Files-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Files in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Flat Files - a file having no internal hierarchy.\n", 15 | "\n", 16 | "e.g - text file, csv file\n", 17 | "\n", 18 | "Modes of file- \n", 19 | "\n", 20 | "Read Mode ('r') - File opened in read mode can not be edited. Only works if a file already exists.\n", 21 | "\n", 22 | "Write Mode ('w') - File opened in write mode can be edited but it completely clears the content in the file. It creates a new file if it don't already exist\n", 23 | "\n", 24 | "Append Mode ('a') - File opened in append mode enables to edit file, but it do not clear the file.\n", 25 | "\n", 26 | "r+ Mode - Opens for read and write, pointer at begining of file, doen't clear the file\n", 27 | "\n", 28 | "w+ Mode - Opens file in read and write and clears the content of file\n", 29 | "\n", 30 | "a+ Mode - Opens file in read and write mode and put the pointer to the end of the file\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 16, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "f = open('myfile.txt', 'w')\n", 48 | "print(type(f))\n", 49 | "\n", 50 | "f.write('Hello World')\n", 51 | "f.close()" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 17, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Hello World\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "file = open('myfile.txt', 'r')\n", 69 | "\n", 70 | "print(file.read())\n", 71 | "file.close()" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 18, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "file = open('myfile.txt', 'a')\n", 81 | "\n", 82 | "file.write('\\nSimple is better than complex')\n", 83 | "file.write('\\nComplex is better than complicated')\n", 84 | "\n", 85 | "file.close()" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "## Do we need close() all the time?" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 19, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "Hello World\n", 105 | "Simple is better than complex\n", 106 | "Complex is better than complicated" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "with open('myfile.txt', 'r') as file:\n", 112 | " for line in file:\n", 113 | " print(line, end = '')" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 21, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "True" 125 | ] 126 | }, 127 | "execution_count": 21, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "file.closed" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 22, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "'myfile.txt'" 145 | ] 146 | }, 147 | "execution_count": 22, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "file.name" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 23, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "data": { 163 | "text/plain": [ 164 | "'r'" 165 | ] 166 | }, 167 | "execution_count": 23, 168 | "metadata": {}, 169 | "output_type": "execute_result" 170 | } 171 | ], 172 | "source": [ 173 | "file.mode" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 33, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "Hello World\n", 186 | "Simple is better than complex\n", 187 | "Complex is better than complicated" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "with open('myfile.txt', 'r') as file:\n", 193 | " for line in file:\n", 194 | " print(line, end = '')" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 40, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "0\n", 207 | "Hello World\n", 208 | "Simple is better than complex\n", 209 | "Complex is better than complicated\n", 210 | "78\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "file = open('myfile.txt', 'r')\n", 216 | "print(file.tell())\n", 217 | "\n", 218 | "for line in file:\n", 219 | " print(line, end = '')\n", 220 | "\n", 221 | "print()\n", 222 | "print(file.tell())\n" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 37, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "print(file.read())" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 38, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "name": "stdout", 249 | "output_type": "stream", 250 | "text": [ 251 | "Hello World\n", 252 | "Simple is better than complex\n", 253 | "Complex is better than complicated\n" 254 | ] 255 | } 256 | ], 257 | "source": [ 258 | "file.seek(0)\n", 259 | "print(file.read())" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 41, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "False" 271 | ] 272 | }, 273 | "execution_count": 41, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "file.closed" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 42, 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [ 288 | "file.close()" 289 | ] 290 | } 291 | ], 292 | "metadata": { 293 | "kernelspec": { 294 | "display_name": "Python 3", 295 | "language": "python", 296 | "name": "python3" 297 | }, 298 | "language_info": { 299 | "codemirror_mode": { 300 | "name": "ipython", 301 | "version": 3 302 | }, 303 | "file_extension": ".py", 304 | "mimetype": "text/x-python", 305 | "name": "python", 306 | "nbconvert_exporter": "python", 307 | "pygments_lexer": "ipython3", 308 | "version": "3.6.4" 309 | } 310 | }, 311 | "nbformat": 4, 312 | "nbformat_minor": 2 313 | } 314 | -------------------------------------------------------------------------------- /Day 2/2. Pandas/.ipynb_checkpoints/pandas-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Pandas in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. It is free software released under the three-clause BSD license.\n", 15 | "\n", 16 | "\n", 17 | "2D NumPy array? - Similar data type\n", 18 | "\n", 19 | "Pandas is a high level data manipulation tool, developed bt Wes McKinney\n", 20 | "\n", 21 | "Pandas is built on NumPy package" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import pandas as pd" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "### Creating DataFrames" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "#### From Lists" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "df = pd.DataFrame([['Bob', 55],\n", 54 | " ['Vien', 52]])" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "type(df)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "print(df)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "#### From NumPy arrays" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "import numpy as np\n", 89 | "\n", 90 | "arr = np.arange(100).reshape(10,10)\n", 91 | "df = pd.DataFrame(arr)\n", 92 | "df" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "df = pd.read_csv('Book1.csv')" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "df" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "## Indexing in DataFrame" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "df['Revenue']" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "df[['Revenue','profit']]" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "### Methods and Attributes in DataFrame" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "Max and Min" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "df['Revenue'].max()" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "df['Revenue'].min()" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "Describing the dataframe" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "df.describe()" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "print(df.columns)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "df.shape" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [ 210 | "df.size" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": { 217 | "scrolled": true 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "df.values" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "df.index = ['ex1', 'ex2', 'ex3']\n", 231 | "df" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "#### Slicing DataFrame using comparision operator" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "df[df['Revenue']>3000]" 248 | ] 249 | }, 250 | { 251 | "cell_type": "markdown", 252 | "metadata": {}, 253 | "source": [ 254 | "### Converting DataFrame to NumPy ndarray" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": null, 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "df.as_matrix()" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "metadata": {}, 269 | "source": [ 270 | "## Importing csv in customized format" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "metadata": {}, 277 | "outputs": [], 278 | "source": [ 279 | "iris_data = pd.read_csv('iris.csv')" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [ 288 | "print(iris_data.head())" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | "iris_data = pd.read_csv('iris.csv', skiprows = 1, usecols = [0, 1, 2, 3], \n", 298 | " names = ['Sepal-Length', 'Spepal-Width', 'Petal-Length', 'Petal-Widht'])" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": null, 304 | "metadata": {}, 305 | "outputs": [], 306 | "source": [ 307 | "print(iris_data.head())" 308 | ] 309 | } 310 | ], 311 | "metadata": { 312 | "kernelspec": { 313 | "display_name": "Python 3", 314 | "language": "python", 315 | "name": "python3" 316 | }, 317 | "language_info": { 318 | "codemirror_mode": { 319 | "name": "ipython", 320 | "version": 3 321 | }, 322 | "file_extension": ".py", 323 | "mimetype": "text/x-python", 324 | "name": "python", 325 | "nbconvert_exporter": "python", 326 | "pygments_lexer": "ipython3", 327 | "version": "3.6.4" 328 | } 329 | }, 330 | "nbformat": 4, 331 | "nbformat_minor": 2 332 | } 333 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/2. Classifier_IRIS.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Classification - Logistic Regression - IRIS problem" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#### Import pandas for importing iris dataset" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import pandas as pd" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "from dataset (iris data) importing 4 features, sepal len & wid, petal len & wid" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "iris_df = pd.read_csv('iris.csv', skiprows=1, names = ['sepal_len', 'sepal_width', 'petal_len', 'petal_width'], usecols=[0,1,2,3])" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "Dataframe heads" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "iris_df.head()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "#### From iris data, importing labels (Setosa, versicolor, verginica), masked as 0,1,2 respectively" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "labels_df = pd.read_csv('iris.csv', skiprows=1, names=['Species'], usecols=[4])" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "labels_df.head()" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "#### Converting dataframe into numpy array using values attribute" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "features = iris_df.values" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "labels = labels_df.values.ravel()" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "The ravel() method returns a flattened (1-Dimensional) NumPy array" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "### Logistic Regression - import" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "from sklearn.model_selection import train_test_split" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "from sklearn.linear_model import LogisticRegression" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "### Split the data into training and testing data, with random seeding" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "x_train, x_test, y_train, y_test = train_test_split(features, labels, test_size=0.30, random_state = 2)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "### Creating an instance of LogisticRegrssion class" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": null, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "logReg = LogisticRegression()" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "### Training the Model / Fitting Data" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "logReg.fit(x_train, y_train)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "metadata": {}, 191 | "source": [ 192 | "### Predicting the label for 1st row in features, cross check with first row in labels" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": { 199 | "scrolled": false 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "print(logReg.predict(x_test[0].reshape(1,-1)))\n", 204 | "print(y_test[0])" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "### Predict for all rows in test data" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "metadata": {}, 218 | "outputs": [], 219 | "source": [ 220 | "predictions = logReg.predict(x_test)" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "The difference here in both is reshape(1,-1), which is used to flatten input if it's only one row, for all rows, we don't use reshaping as flat array because it doen't make sense" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "### Score Model" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "score = logReg.score(x_test, y_test)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "metadata": { 250 | "scrolled": true 251 | }, 252 | "outputs": [], 253 | "source": [ 254 | "print('Score: ', score)" 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": {}, 260 | "source": [ 261 | "Score of 0.93 means the model we just created gave out correct results for 93% of the test data" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "metadata": {}, 267 | "source": [ 268 | "### Confusion Matrix" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": null, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "from sklearn.metrics import confusion_matrix" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "cm = confusion_matrix(predictions, y_test)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [ 295 | "print(cm)" 296 | ] 297 | } 298 | ], 299 | "metadata": { 300 | "kernelspec": { 301 | "display_name": "Python 3", 302 | "language": "python", 303 | "name": "python3" 304 | }, 305 | "language_info": { 306 | "codemirror_mode": { 307 | "name": "ipython", 308 | "version": 3 309 | }, 310 | "file_extension": ".py", 311 | "mimetype": "text/x-python", 312 | "name": "python", 313 | "nbconvert_exporter": "python", 314 | "pygments_lexer": "ipython3", 315 | "version": "3.6.4" 316 | } 317 | }, 318 | "nbformat": 4, 319 | "nbformat_minor": 2 320 | } 321 | -------------------------------------------------------------------------------- /Day 2/4. Classifiers/.ipynb_checkpoints/Classifier_IRIS-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Classification - Logistic Regression - IRIS problem" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#### Import pandas for importing iris dataset" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import pandas as pd" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "from dataset (iris data) importing 4 features, sepal len & wid, petal len & wid" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "iris_df = pd.read_csv('iris.csv', skiprows=1, names = ['sepal_len', 'sepal_width', 'petal_len', 'petal_width'], usecols=[0,1,2,3])" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "Dataframe heads" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "iris_df.head()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "#### From iris data, importing labels (Setosa, versicolor, verginica), masked as 0,1,2 respectively" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "labels_df = pd.read_csv('iris.csv', skiprows=1, names=['Species'], usecols=[4])" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "labels_df.head()" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "#### Converting dataframe into numpy array using values attribute" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "features = iris_df.values" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "labels = labels_df.values.ravel()" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "The ravel() method returns a flattened (1-Dimensional) NumPy array" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "### Logistic Regression - import" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "from sklearn.model_selection import train_test_split" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "from sklearn.linear_model import LogisticRegression" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "### Split the data into training and testing data, with random seeding" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "x_train, x_test, y_train, y_test = train_test_split(features, labels, test_size=0.30, random_state = 2)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "### Creating an instance of LogisticRegrssion class" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": null, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "logReg = LogisticRegression()" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "### Training the Model / Fitting Data" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "logReg.fit(x_train, y_train)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "metadata": {}, 191 | "source": [ 192 | "### Predicting the label for 1st row in features, cross check with first row in labels" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": { 199 | "scrolled": false 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "print(logReg.predict(x_test[0].reshape(1,-1)))\n", 204 | "print(y_test[0])" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "### Predict for all rows in test data" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "metadata": {}, 218 | "outputs": [], 219 | "source": [ 220 | "predictions = logReg.predict(x_test)" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "The difference here in both is reshape(1,-1), which is used to flatten input if it's only one row, for all rows, we don't use reshaping as flat array because it doen't make sense" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "### Score Model" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "score = logReg.score(x_test, y_test)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "metadata": { 250 | "scrolled": true 251 | }, 252 | "outputs": [], 253 | "source": [ 254 | "print('Score: ', score)" 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": {}, 260 | "source": [ 261 | "Score of 0.93 means the model we just created gave out correct results for 93% of the test data" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "metadata": {}, 267 | "source": [ 268 | "### Confusion Matrix" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": null, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "from sklearn.metrics import confusion_matrix" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "cm = confusion_matrix(predictions, y_test)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [ 295 | "print(cm)" 296 | ] 297 | } 298 | ], 299 | "metadata": { 300 | "kernelspec": { 301 | "display_name": "Python 3", 302 | "language": "python", 303 | "name": "python3" 304 | }, 305 | "language_info": { 306 | "codemirror_mode": { 307 | "name": "ipython", 308 | "version": 3 309 | }, 310 | "file_extension": ".py", 311 | "mimetype": "text/x-python", 312 | "name": "python", 313 | "nbconvert_exporter": "python", 314 | "pygments_lexer": "ipython3", 315 | "version": "3.6.4" 316 | } 317 | }, 318 | "nbformat": 4, 319 | "nbformat_minor": 2 320 | } 321 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/2. Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Strings in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "data": { 17 | "text/plain": [ 18 | "True" 19 | ] 20 | }, 21 | "execution_count": 1, 22 | "metadata": {}, 23 | "output_type": "execute_result" 24 | } 25 | ], 26 | "source": [ 27 | "'Hello' is \"Hello\"" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 2, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "data": { 37 | "text/plain": [ 38 | "True" 39 | ] 40 | }, 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "output_type": "execute_result" 44 | } 45 | ], 46 | "source": [ 47 | "'Hello' == \"Hello\"" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "### Strings can be indexed, sliced" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "H\n", 67 | "e\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "a = 'Hello World'\n", 73 | "print(a[0])\n", 74 | "print(a[1])" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "Hello \n", 87 | "World\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "print(a[:6])\n", 93 | "print(a[6:])" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "### The first and last spaces in string - strip() method" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 12, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "a = Hello World \n", 113 | "Length of a: 13\n", 114 | "b = Hello World\n", 115 | "Length of b: 11\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "a = ' Hello World '\n", 121 | "print('a =', a)\n", 122 | "print('Length of a: ', len(a))\n", 123 | "\n", 124 | "b = a.strip()\n", 125 | "print('b =', b)\n", 126 | "print('Length of b: ', len(b))" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "### Length of string, case of string" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 13, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "11\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "a = \"Hello World\"\n", 151 | "print(len(a))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 16, 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "hello world\n", 164 | "HELLO WORLD\n", 165 | "Hello World\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "x = a.lower()\n", 171 | "print(x)\n", 172 | "\n", 173 | "y = a.upper()\n", 174 | "print(y)\n", 175 | "\n", 176 | "z = a.title()\n", 177 | "print(z)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "## Strings are not mutable in Python" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 17, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "2273901629032\n", 197 | "2273901626624\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "a = 'Dog'\n", 203 | "print(id(a))\n", 204 | "\n", 205 | "a = 'Cat'\n", 206 | "print(id(a))" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "#### Though strings aren't mutable (immutable) you can still change what the variable points to,\n", 214 | "#### In above example, first a pointed to 'Dog' at different location and then it pointed to 'Cat' at different memory address" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 22, 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "name": "stdout", 224 | "output_type": "stream", 225 | "text": [ 226 | "2273901562160\n", 227 | "2273901562160\n", 228 | "Hello World\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "a = 'Hello World'\n", 234 | "print(id(a))\n", 235 | "\n", 236 | "a.replace('o', 'a')\n", 237 | "print(id(a))\n", 238 | "\n", 239 | "print(a)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 23, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "ename": "TypeError", 249 | "evalue": "'str' object does not support item assignment", 250 | "output_type": "error", 251 | "traceback": [ 252 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 253 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 254 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Hello World'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'h'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 255 | "\u001b[1;31mTypeError\u001b[0m: 'str' object does not support item assignment" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "a = 'Hello World'\n", 261 | "a[0] = 'h'" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "metadata": {}, 267 | "source": [ 268 | "## Converting string to list of strings - split()" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 25, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "name": "stdout", 278 | "output_type": "stream", 279 | "text": [ 280 | "['Hello', 'My', 'name', 'is', 'Naveen']\n" 281 | ] 282 | } 283 | ], 284 | "source": [ 285 | "a = \"Hello My name is Naveen\"\n", 286 | "\n", 287 | "b = a.split()\n", 288 | "print(b)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": {}, 294 | "source": [ 295 | "By default, split considers any blank space as delimiter" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 27, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "name": "stdout", 305 | "output_type": "stream", 306 | "text": [ 307 | "['Delhi', 'Jaipur']\n" 308 | ] 309 | } 310 | ], 311 | "source": [ 312 | "a = 'Delhi:Jaipur'\n", 313 | "\n", 314 | "b = a.split(':')\n", 315 | "print(b)" 316 | ] 317 | }, 318 | { 319 | "cell_type": "markdown", 320 | "metadata": {}, 321 | "source": [ 322 | "### Converting to string from list items" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 28, 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "name": "stdout", 332 | "output_type": "stream", 333 | "text": [ 334 | "HelloWorld\n" 335 | ] 336 | } 337 | ], 338 | "source": [ 339 | "s = ''\n", 340 | "lst = ['Hello', 'World']\n", 341 | "\n", 342 | "for i in lst:\n", 343 | " s += i\n", 344 | "\n", 345 | "print(s)" 346 | ] 347 | } 348 | ], 349 | "metadata": { 350 | "kernelspec": { 351 | "display_name": "Python 3", 352 | "language": "python", 353 | "name": "python3" 354 | }, 355 | "language_info": { 356 | "codemirror_mode": { 357 | "name": "ipython", 358 | "version": 3 359 | }, 360 | "file_extension": ".py", 361 | "mimetype": "text/x-python", 362 | "name": "python", 363 | "nbconvert_exporter": "python", 364 | "pygments_lexer": "ipython3", 365 | "version": "3.6.4" 366 | } 367 | }, 368 | "nbformat": 4, 369 | "nbformat_minor": 2 370 | } 371 | -------------------------------------------------------------------------------- /Day 1/2. Strings Standard Input and Files/.ipynb_checkpoints/Strings-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Strings in Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "data": { 17 | "text/plain": [ 18 | "True" 19 | ] 20 | }, 21 | "execution_count": 1, 22 | "metadata": {}, 23 | "output_type": "execute_result" 24 | } 25 | ], 26 | "source": [ 27 | "'Hello' is \"Hello\"" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 2, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "data": { 37 | "text/plain": [ 38 | "True" 39 | ] 40 | }, 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "output_type": "execute_result" 44 | } 45 | ], 46 | "source": [ 47 | "'Hello' == \"Hello\"" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "### Strings can be indexed, sliced" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "H\n", 67 | "e\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "a = 'Hello World'\n", 73 | "print(a[0])\n", 74 | "print(a[1])" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "Hello \n", 87 | "World\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "print(a[:6])\n", 93 | "print(a[6:])" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "### The first and last spaces in string - strip() method" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 12, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "a = Hello World \n", 113 | "Length of a: 13\n", 114 | "b = Hello World\n", 115 | "Length of b: 11\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "a = ' Hello World '\n", 121 | "print('a =', a)\n", 122 | "print('Length of a: ', len(a))\n", 123 | "\n", 124 | "b = a.strip()\n", 125 | "print('b =', b)\n", 126 | "print('Length of b: ', len(b))" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "### Length of string, case of string" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 13, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "11\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "a = \"Hello World\"\n", 151 | "print(len(a))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 16, 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "hello world\n", 164 | "HELLO WORLD\n", 165 | "Hello World\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "x = a.lower()\n", 171 | "print(x)\n", 172 | "\n", 173 | "y = a.upper()\n", 174 | "print(y)\n", 175 | "\n", 176 | "z = a.title()\n", 177 | "print(z)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "## Strings are not mutable in Python" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 17, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "2273901629032\n", 197 | "2273901626624\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "a = 'Dog'\n", 203 | "print(id(a))\n", 204 | "\n", 205 | "a = 'Cat'\n", 206 | "print(id(a))" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "#### Though strings aren't mutable (immutable) you can still change what the variable points to,\n", 214 | "#### In above example, first a pointed to 'Dog' at different location and then it pointed to 'Cat' at different memory address" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 22, 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "name": "stdout", 224 | "output_type": "stream", 225 | "text": [ 226 | "2273901562160\n", 227 | "2273901562160\n", 228 | "Hello World\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "a = 'Hello World'\n", 234 | "print(id(a))\n", 235 | "\n", 236 | "a.replace('o', 'a')\n", 237 | "print(id(a))\n", 238 | "\n", 239 | "print(a)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 23, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "ename": "TypeError", 249 | "evalue": "'str' object does not support item assignment", 250 | "output_type": "error", 251 | "traceback": [ 252 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 253 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 254 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Hello World'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'h'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 255 | "\u001b[1;31mTypeError\u001b[0m: 'str' object does not support item assignment" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "a = 'Hello World'\n", 261 | "a[0] = 'h'" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "metadata": {}, 267 | "source": [ 268 | "## Converting string to list of strings - split()" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 25, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "name": "stdout", 278 | "output_type": "stream", 279 | "text": [ 280 | "['Hello', 'My', 'name', 'is', 'Naveen']\n" 281 | ] 282 | } 283 | ], 284 | "source": [ 285 | "a = \"Hello My name is Naveen\"\n", 286 | "\n", 287 | "b = a.split()\n", 288 | "print(b)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": {}, 294 | "source": [ 295 | "By default, split considers any blank space as delimiter" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 27, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "name": "stdout", 305 | "output_type": "stream", 306 | "text": [ 307 | "['Delhi', 'Jaipur']\n" 308 | ] 309 | } 310 | ], 311 | "source": [ 312 | "a = 'Delhi:Jaipur'\n", 313 | "\n", 314 | "b = a.split(':')\n", 315 | "print(b)" 316 | ] 317 | }, 318 | { 319 | "cell_type": "markdown", 320 | "metadata": {}, 321 | "source": [ 322 | "### Converting to string from list items" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 28, 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "name": "stdout", 332 | "output_type": "stream", 333 | "text": [ 334 | "HelloWorld\n" 335 | ] 336 | } 337 | ], 338 | "source": [ 339 | "s = ''\n", 340 | "lst = ['Hello', 'World']\n", 341 | "\n", 342 | "for i in lst:\n", 343 | " s += i\n", 344 | "\n", 345 | "print(s)" 346 | ] 347 | } 348 | ], 349 | "metadata": { 350 | "kernelspec": { 351 | "display_name": "Python 3", 352 | "language": "python", 353 | "name": "python3" 354 | }, 355 | "language_info": { 356 | "codemirror_mode": { 357 | "name": "ipython", 358 | "version": 3 359 | }, 360 | "file_extension": ".py", 361 | "mimetype": "text/x-python", 362 | "name": "python", 363 | "nbconvert_exporter": "python", 364 | "pygments_lexer": "ipython3", 365 | "version": "3.6.4" 366 | } 367 | }, 368 | "nbformat": 4, 369 | "nbformat_minor": 2 370 | } 371 | -------------------------------------------------------------------------------- /Day 2/1. NumPy Revision Tour/Untitled.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# NumPy" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "NumPy is a python library, short for numeric python" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Why Numpy?" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "Python has many builtin types of collections, including tuples, lists and sets, which have their own purpose and benefits, however, we still miss the array we got used to in c and c++\n", 29 | "\n", 30 | "You might say I'm gotta be kidding because most of us hated arrays didn't we? But here's the thing-\n", 31 | "\n", 32 | "In an array we stored only on type of elements, for an integer array we only stored ints and same for floats and character. Why does that matter? \n", 33 | "\n", 34 | "Because sometimes you might wanna perform an operation on entire array, for example let's say you have a list to store heights of people in your calss and you want to find the mean of that list, you'll have to write a function to do that, and even before that you'll need to make sure that the list contains only heights in floats.\n", 35 | "\n", 36 | "Doesn't make sense? Let's suppose you've been more collective about data and now you want both heights and weights of students. You have a 2D list with two columns, first one with heights and second one with weights. Let's see-" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "Data = [[1.74, 1.45, 1.58, 1.80],\n", 46 | " [58.2, 60.0, 61.2, 63.2]] " 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "heights = Data[0]\n", 56 | "weights = Data[1]" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "[1.74, 1.45, 1.58, 1.8]\n", 69 | "[58.2, 60.0, 61.2, 63.2]\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(heights)\n", 75 | "print(weights)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "Suppose you want BMI or Body Mass Index of every person\n", 83 | "\n", 84 | "BMI = weight (in kgs.) / (heights (in mtr.))^2" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 4, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "ename": "TypeError", 94 | "evalue": "unsupported operand type(s) for ** or pow(): 'list' and 'int'", 95 | "output_type": "error", 96 | "traceback": [ 97 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 98 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 99 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mBMI\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mweights\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mheights\u001b[0m \u001b[1;33m**\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 100 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'list' and 'int'" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "BMI = weights / heights ** 2" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 5, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "name": "stdout", 115 | "output_type": "stream", 116 | "text": [ 117 | "[19.223147047166073, 28.53745541022592, 24.515302034930297, 19.506172839506174]\n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "BMI = []\n", 123 | "for weight, height in zip(weights, heights):\n", 124 | " BMI.append(weight / height ** 2)\n", 125 | "\n", 126 | "print(BMI)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "### With NumPy|" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 2, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "import numpy as np" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 7, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "np_heights = np.array(heights)\n", 152 | "np_weights = np.array(weights)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 8, 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "bmi = np_weights / np_heights ** 2" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 9, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "[19.22314705 28.53745541 24.51530203 19.50617284]\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "print(bmi)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "metadata": {}, 184 | "source": [ 185 | "### Why does that even matter?" 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "metadata": {}, 191 | "source": [ 192 | "This was a data for only four people, what if you a have a million rows of data?" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 3, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "np_heights = np.round(np.random.normal(1.75, 0.20, 5000), 2)\n", 202 | "np_weights = np.round(np.random.normal(60.32, 15, 5000), 2)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 11, 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "name": "stdout", 212 | "output_type": "stream", 213 | "text": [ 214 | "[1.95 1.62 1.51 ... 1.67 1.6 1.83]\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "print(np_heights)" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 12, 225 | "metadata": {}, 226 | "outputs": [ 227 | { 228 | "data": { 229 | "text/plain": [ 230 | "(5000,)" 231 | ] 232 | }, 233 | "execution_count": 12, 234 | "metadata": {}, 235 | "output_type": "execute_result" 236 | } 237 | ], 238 | "source": [ 239 | "np_heights.shape" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 13, 245 | "metadata": {}, 246 | "outputs": [], 247 | "source": [ 248 | "BMI = np_weights / np_heights ** 2" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 14, 254 | "metadata": { 255 | "scrolled": true 256 | }, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "[15.16633794 33.49718031 14.31077584 ... 28.95765356 19.00390625\n", 263 | " 20.22156529]\n" 264 | ] 265 | } 266 | ], 267 | "source": [ 268 | "print(BMI)" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 4, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "np_data = np.column_stack((np_heights, np_weights))" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "### More with NumPy\n", 285 | "\n", 286 | "Calculating mean median" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 15, 292 | "metadata": {}, 293 | "outputs": [ 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "1.7506219999999997" 298 | ] 299 | }, 300 | "execution_count": 15, 301 | "metadata": {}, 302 | "output_type": "execute_result" 303 | } 304 | ], 305 | "source": [ 306 | "np.mean(np_heights)" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 16, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "data": { 316 | "text/plain": [ 317 | "1.75" 318 | ] 319 | }, 320 | "execution_count": 16, 321 | "metadata": {}, 322 | "output_type": "execute_result" 323 | } 324 | ], 325 | "source": [ 326 | "np.median(np_heights)" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "metadata": {}, 332 | "source": [ 333 | "### Corelation coefficient\n", 334 | "\n", 335 | "--More in stats--\n", 336 | "\n", 337 | "Corelation coefficient is a number between -1 and 1 that signifies how closely two variables x and y (e.g. heights and weights) that belong to same record, depend on each other" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 17, 343 | "metadata": {}, 344 | "outputs": [ 345 | { 346 | "data": { 347 | "text/plain": [ 348 | "array([[ 1. , -0.00283161],\n", 349 | " [-0.00283161, 1. ]])" 350 | ] 351 | }, 352 | "execution_count": 17, 353 | "metadata": {}, 354 | "output_type": "execute_result" 355 | } 356 | ], 357 | "source": [ 358 | "np.corrcoef(np_heights, np_weights)" 359 | ] 360 | } 361 | ], 362 | "metadata": { 363 | "kernelspec": { 364 | "display_name": "Python 3", 365 | "language": "python", 366 | "name": "python3" 367 | }, 368 | "language_info": { 369 | "codemirror_mode": { 370 | "name": "ipython", 371 | "version": 3 372 | }, 373 | "file_extension": ".py", 374 | "mimetype": "text/x-python", 375 | "name": "python", 376 | "nbconvert_exporter": "python", 377 | "pygments_lexer": "ipython3", 378 | "version": "3.6.4" 379 | } 380 | }, 381 | "nbformat": 4, 382 | "nbformat_minor": 2 383 | } 384 | --------------------------------------------------------------------------------