├── .idea ├── .name ├── encodings.xml ├── vcs.xml ├── modules.xml ├── py.iml └── misc.xml ├── unittesting_pytest ├── init.py ├── fixtures │ ├── __init__.py │ ├── test_mydb.py │ └── mydb.py ├── parametrize │ ├── mathlib.py │ └── test_mathlib.py └── custom_markers │ ├── mathlib.py │ └── test_mathlib.py ├── Basics ├── caller.py ├── Hindi │ ├── 10_name_ │ │ ├── caller.py │ │ └── utility.py │ ├── 12_read_write_file │ │ ├── love.txt │ │ ├── funny.txt │ │ ├── Exercise │ │ │ ├── output.csv │ │ │ ├── stocks.csv │ │ │ ├── exercise_2_stocks.py │ │ │ ├── exercise_1_poem.py │ │ │ └── poem.txt │ │ ├── scores.csv │ │ ├── read_write_file_exercise.md │ │ └── 12_read_write_file.py │ ├── 7_for │ │ ├── for_loop.py │ │ ├── 7_for.py │ │ ├── 7_for_exercise.md │ │ └── Exercise │ │ │ └── 7_for_exercise.py │ ├── 4_user_input │ │ ├── 4_user_input.py │ │ ├── 4_user_input_exercise.md │ │ └── Exercise │ │ │ └── 4_user_input_exercise.py │ ├── 9_modules │ │ ├── main.py │ │ ├── utility │ │ │ └── area.py │ │ └── 9_modules.ipynb │ ├── 11_dict_tuple │ │ ├── Exercise │ │ │ ├── 11_dict_exercise_3_circle.py │ │ │ ├── 11_dict_exercise_2_stocks.py │ │ │ └── 11_dict_exercise_1_country_population.py │ │ └── 11_dict_tuple_exercise.md │ ├── 6_if │ │ ├── Exercise │ │ │ ├── 6_exercise2.py │ │ │ ├── 6_exercise1_1.py │ │ │ └── 6_exercise1_2.py │ │ ├── 6_if.py │ │ └── 6_exercise_description.md │ ├── 1_Variables │ │ ├── 1_variables_exercise.md │ │ ├── 1_variables.py │ │ └── Exercise │ │ │ └── 1_variables_exercise.ipynb │ ├── 2_numbers │ │ ├── 2_numbers_exercise_description.md │ │ ├── 2_numbers.py │ │ └── Exercise │ │ │ └── 2_numbers_exercise.py │ ├── 8_functions │ │ ├── 8_functions_exercise.md │ │ ├── 8_functions.py │ │ └── Exercise │ │ │ └── 8_functions_exercise.py │ ├── 3_strings │ │ ├── 3_strings_exercise.md │ │ └── Exercise │ │ │ └── 3_string_exercise_answer.py │ └── 5_lists │ │ ├── 5_lists_exercise.md │ │ └── Exercise │ │ └── 5_lists_exercise.py ├── input.txt ├── test.py ├── myprogram.py ├── 22_Generators.py ├── area.py ├── word_occurences.py ├── 20_raise_exception.py ├── 16_exception.py ├── address.py ├── 19_multiple_inheritance.py ├── 21_iterators.py ├── 17_class.py ├── 14_json_addressbook.py ├── 18_inheritance.py ├── 13_read_write_file.py ├── lists ├── dict_tuple.py ├── if.py ├── variable_numbers_strings.py ├── for.py └── functions.py ├── numpy ├── numpy_tutorail_2.py └── numpy_tutorial.py ├── ML ├── 13_kmeans │ ├── iris.png │ └── income.csv ├── 11_random_forest │ ├── iris.png │ └── forest.jpg ├── 1_linear_reg │ ├── equation.PNG │ ├── scatterplot.JPG │ ├── error_equation.jpg │ ├── homepricetable.JPG │ ├── different_lines.JPG │ ├── linear_equation.png │ ├── homeprices.csv │ ├── areas.csv │ ├── prediction.csv │ ├── linearReg.py │ └── Exercise │ │ └── canada_per_capita_income.csv ├── 4_save_model │ ├── model_joblib │ ├── model_pickle │ └── homeprices.csv ├── 10_svm │ └── iris_petal_sepal.png ├── 9_decision_tree │ ├── titanic.jpg │ └── salaries.csv ├── 15_gridsearch │ ├── iris_petal_sepal.png │ ├── exercise.md │ └── Exercise │ │ └── 15_grid_search_cv_exercise.ipynb ├── 2_linear_reg_multivariate │ ├── equation.jpg │ ├── homeprices.jpg │ ├── home_equation.jpg │ ├── general_equation.jpg │ ├── homeprices.csv │ └── Exercise │ │ └── hiring.csv ├── 8_logistic_reg_multiclass │ └── iris_petal_sepal.png ├── 3_gradient_descent │ ├── Exercise │ │ ├── test_scores.csv │ │ └── ex_gradient_descent.py │ └── gradient_descent.py ├── 7_logistic_reg │ └── insurance_data.csv ├── 6_train_test_split │ └── carprices.csv ├── 5_one_hot_encoding │ ├── homeprices.csv │ └── Exercise │ │ └── carprices.csv ├── 14_naive_bayes │ └── exercise.md └── 12_KFold_Cross_Validation │ └── Exercise │ └── exercise_kfold_validation.ipynb ├── pandas ├── 12_stack │ ├── stocks.xlsx │ └── stocks_3_levels.xlsx ├── 21_sql │ ├── db_tables.jpg │ ├── conn_string_format.JPG │ └── customers.csv ├── 9_merge │ └── db_joins.jpg ├── 13_crosstab │ └── survey.xls ├── 19_ts_timezone │ ├── alignment.png │ ├── timezones_world_map.png │ └── msft.csv ├── 20_shift_lag │ ├── shift_image.png │ └── fb.csv ├── 4_read_write_to_excel │ ├── new.csv │ ├── new.xlsx │ ├── stock_data.xlsx │ ├── stocks_weather.xlsx │ ├── read_write_with_flask │ │ ├── example2.xlsx │ │ ├── static │ │ │ └── style.css │ │ ├── flask_with_excel.py │ │ └── templates │ │ │ └── index.html │ ├── stock_data.csv │ └── read_write_excel_file.txt ├── 7_group_by │ ├── group_by_cities.png │ ├── split_apply_combine.png │ └── weather_by_cities.csv ├── 3_different_ways_of_creating_dataframe │ ├── weather_data.csv │ └── weather_data.xlsx ├── 5_handling_missing_data_fillna_dropna_interpolate │ ├── missing_data.txt │ ├── weather_data.xls │ └── weather_data.csv ├── 11_melt │ └── weather.csv ├── 18_ts_period │ └── wmt.csv ├── 2_dataframe_basics │ └── weather_data.csv ├── 10_pivot │ ├── weather3.csv │ ├── weather2.csv │ └── weather.csv ├── 6_handling_missing_data_replace │ └── weather_data.csv ├── 16_ts_holidays │ ├── aapl_no_dates.csv │ └── aapl.csv ├── 15_ts_date_range │ ├── aapl_no_dates.csv │ └── aapl.csv ├── contents.txt └── 1_intro │ ├── nyc_weather.csv │ ├── pandas_intro.py │ └── Pandas_introduction.ipynb ├── .gitignore ├── DataScience └── BangloreHomePrices │ ├── server │ ├── requirements.txt │ ├── artifacts │ │ ├── banglore_home_prices_model.pickle │ │ └── columns.json │ ├── server.py │ └── util.py │ ├── BHP_website.PNG │ ├── model │ ├── hebbal_outliers.png │ ├── rajaji_nagar_outliers.png │ ├── banglore_home_prices_model.pickle │ └── columns.json │ ├── nginx_files │ └── bhp.conf │ ├── client │ ├── app.html │ ├── app.js │ └── app.css │ └── readme.md ├── jupyter ├── jupyter_architecture.png └── pandas_tutorial_on_stock_price.py ├── matpltlib ├── 7_save_chart │ ├── piechart.png │ └── 7_exercise_save_chart.PNG └── 10_subplots.ipynb ├── DataStructures ├── 5_Stack │ ├── dynamic_memory.png │ ├── Exercise │ │ ├── reverse_string.py │ │ └── balance_paran.py │ └── 5_stack_exercise.md ├── 4_HashTable │ └── stock_prices.csv ├── 4_HashTable_2_Collisions │ ├── Solution │ │ ├── nyc_weather.csv │ │ ├── poem.txt │ │ └── exercise_poem_find_word_occurances.ipynb │ └── 4_hash_table_exercise.md ├── 2_Arrays │ ├── Solution │ │ ├── 3_odd_even_numbers.py │ │ ├── 2_marvel.py │ │ └── 1_expenses.py │ └── 2_arrays_exercise.md └── 3_LinkedList │ ├── 3_linked_list_exercise.md │ ├── 3_linked_list.py │ └── Solution │ ├── doubly_linked_list_exercise.py │ └── singly_linked_list_exercise.py ├── Debugging ├── watches_callstack.py ├── debugging.py ├── expenses.txt └── conditional_breakpoint.py ├── README.md ├── DeepLearningML └── 1_keras_fashion_mnist_neural_net │ ├── Slide1.PNG │ ├── Slide2.PNG │ ├── fmnist.png │ ├── classlabels.JPG │ └── fashion_neural_net.png ├── TechTopics ├── ResumeDataAnalyst │ ├── Resume_data_analyst_fresher.pdf │ └── Resume_data_analyst_experienced.pdf └── HowToLearnProgramming │ ├── 11_steps_learn_programming.png │ ├── nishant_effective_learning.png │ └── how_to_learn_programming.md ├── Modules ├── urllib_demo.py ├── pandas_tutorial.py └── argparse_tutorial.py ├── Multiprocessing ├── multiprocessing_pool.py ├── multiprocessing_queue_pipe.py ├── multithreading_producer_consumer.py ├── multiprocessing_value_array.py ├── multiprocessing_introduction.py ├── multthreading_introduction.py └── multiprocessing_lock.py └── Advanced └── decorators.py /.idea/.name: -------------------------------------------------------------------------------- 1 | py -------------------------------------------------------------------------------- /unittesting_pytest/init.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /unittesting_pytest/fixtures/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Basics/caller.py: -------------------------------------------------------------------------------- 1 | import area 2 | print("I am in caller.py") 3 | area.calculate_area(5,10) -------------------------------------------------------------------------------- /numpy/numpy_tutorail_2.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a=np.array([[1,2,3],[4,5,6]]) 4 | -------------------------------------------------------------------------------- /unittesting_pytest/parametrize/mathlib.py: -------------------------------------------------------------------------------- 1 | def calc_square(num): 2 | return num*num -------------------------------------------------------------------------------- /Basics/Hindi/10_name_/caller.py: -------------------------------------------------------------------------------- 1 | import utility 2 | 3 | print("In caller.py: ",__name__) 4 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/love.txt: -------------------------------------------------------------------------------- 1 | I love python 2 | I love javascript 3 | I love C++ -------------------------------------------------------------------------------- /ML/13_kmeans/iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/13_kmeans/iris.png -------------------------------------------------------------------------------- /Basics/input.txt: -------------------------------------------------------------------------------- 1 | sum: 14 | 6,8 2 | sum: 13 | 7,6 3 | sum: 10 | 2,8 4 | sum: 14 | 9,5 5 | sum: 15 | 9,6 -------------------------------------------------------------------------------- /pandas/12_stack/stocks.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/12_stack/stocks.xlsx -------------------------------------------------------------------------------- /pandas/21_sql/db_tables.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/21_sql/db_tables.jpg -------------------------------------------------------------------------------- /pandas/9_merge/db_joins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/9_merge/db_joins.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .idea/ 3 | **/.idea/ 4 | .ipynb_checkpoints/ 5 | **/.ipynb_checkpoints/ 6 | **/.cache/ -------------------------------------------------------------------------------- /Basics/Hindi/7_for/for_loop.py: -------------------------------------------------------------------------------- 1 | # while loop 2 | n=0 3 | 4 | while n<=10: 5 | print(n) 6 | n=n+1 7 | -------------------------------------------------------------------------------- /ML/11_random_forest/iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/11_random_forest/iris.png -------------------------------------------------------------------------------- /ML/1_linear_reg/equation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/equation.PNG -------------------------------------------------------------------------------- /ML/4_save_model/model_joblib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/4_save_model/model_joblib -------------------------------------------------------------------------------- /ML/4_save_model/model_pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/4_save_model/model_pickle -------------------------------------------------------------------------------- /pandas/13_crosstab/survey.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/13_crosstab/survey.xls -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/server/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==1.0.2 2 | numpy==1.16.2 3 | scikit-learn==0.20.3 -------------------------------------------------------------------------------- /ML/10_svm/iris_petal_sepal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/10_svm/iris_petal_sepal.png -------------------------------------------------------------------------------- /ML/11_random_forest/forest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/11_random_forest/forest.jpg -------------------------------------------------------------------------------- /ML/1_linear_reg/scatterplot.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/scatterplot.JPG -------------------------------------------------------------------------------- /ML/9_decision_tree/titanic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/9_decision_tree/titanic.jpg -------------------------------------------------------------------------------- /jupyter/jupyter_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/jupyter/jupyter_architecture.png -------------------------------------------------------------------------------- /ML/1_linear_reg/error_equation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/error_equation.jpg -------------------------------------------------------------------------------- /ML/1_linear_reg/homepricetable.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/homepricetable.JPG -------------------------------------------------------------------------------- /ML/15_gridsearch/iris_petal_sepal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/15_gridsearch/iris_petal_sepal.png -------------------------------------------------------------------------------- /ML/1_linear_reg/different_lines.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/different_lines.JPG -------------------------------------------------------------------------------- /ML/1_linear_reg/linear_equation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/1_linear_reg/linear_equation.png -------------------------------------------------------------------------------- /matpltlib/7_save_chart/piechart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/matpltlib/7_save_chart/piechart.png -------------------------------------------------------------------------------- /pandas/12_stack/stocks_3_levels.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/12_stack/stocks_3_levels.xlsx -------------------------------------------------------------------------------- /pandas/19_ts_timezone/alignment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/19_ts_timezone/alignment.png -------------------------------------------------------------------------------- /pandas/20_shift_lag/shift_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/20_shift_lag/shift_image.png -------------------------------------------------------------------------------- /pandas/21_sql/conn_string_format.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/21_sql/conn_string_format.JPG -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/new.csv: -------------------------------------------------------------------------------- 1 | tickers,price 2 | GOOGL,845 3 | WMT,65 4 | MSFT,64 5 | RIL ,1023 6 | TATA,n.a. 7 | -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/new.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/4_read_write_to_excel/new.xlsx -------------------------------------------------------------------------------- /pandas/7_group_by/group_by_cities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/7_group_by/group_by_cities.png -------------------------------------------------------------------------------- /ML/1_linear_reg/homeprices.csv: -------------------------------------------------------------------------------- 1 | area,price 2 | 2600,550000 3 | 3000,565000 4 | 3200,610000 5 | 3600,680000 6 | 4000,725000 7 | -------------------------------------------------------------------------------- /ML/4_save_model/homeprices.csv: -------------------------------------------------------------------------------- 1 | area,price 2 | 2600,550000 3 | 3000,565000 4 | 3200,610000 5 | 3600,680000 6 | 4000,725000 7 | -------------------------------------------------------------------------------- /DataStructures/5_Stack/dynamic_memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataStructures/5_Stack/dynamic_memory.png -------------------------------------------------------------------------------- /Debugging/watches_callstack.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | bar() 3 | 4 | def bar(): 5 | pass 6 | 7 | foo() 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/equation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/2_linear_reg_multivariate/equation.jpg -------------------------------------------------------------------------------- /pandas/7_group_by/split_apply_combine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/7_group_by/split_apply_combine.png -------------------------------------------------------------------------------- /DataStructures/4_HashTable/stock_prices.csv: -------------------------------------------------------------------------------- 1 | march 6,310 2 | march 7,340 3 | march 8,380 4 | march 9,302 5 | march 10,297 6 | march 11,323 -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/homeprices.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/2_linear_reg_multivariate/homeprices.jpg -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/stock_data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/4_read_write_to_excel/stock_data.xlsx -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/BHP_website.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataScience/BangloreHomePrices/BHP_website.PNG -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/home_equation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/2_linear_reg_multivariate/home_equation.jpg -------------------------------------------------------------------------------- /pandas/19_ts_timezone/timezones_world_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/19_ts_timezone/timezones_world_map.png -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/general_equation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/2_linear_reg_multivariate/general_equation.jpg -------------------------------------------------------------------------------- /ML/8_logistic_reg_multiclass/iris_petal_sepal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/ML/8_logistic_reg_multiclass/iris_petal_sepal.png -------------------------------------------------------------------------------- /matpltlib/7_save_chart/7_exercise_save_chart.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/matpltlib/7_save_chart/7_exercise_save_chart.PNG -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/stocks_weather.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/4_read_write_to_excel/stocks_weather.xlsx -------------------------------------------------------------------------------- /Basics/Hindi/4_user_input/4_user_input.py: -------------------------------------------------------------------------------- 1 | n1=input("Enter first number") 2 | n2=input("Enter second number") 3 | sum=float(n1)+float(n2) 4 | print("Sum is:",sum) -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/model/hebbal_outliers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataScience/BangloreHomePrices/model/hebbal_outliers.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # py 2 | Repository to store sample python programs for python learning 3 | Youtube channel https://www.youtube.com/channel/UCh9nVJoWXmFb7sLApWGcLPQ 4 | -------------------------------------------------------------------------------- /DeepLearningML/1_keras_fashion_mnist_neural_net/Slide1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DeepLearningML/1_keras_fashion_mnist_neural_net/Slide1.PNG -------------------------------------------------------------------------------- /DeepLearningML/1_keras_fashion_mnist_neural_net/Slide2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DeepLearningML/1_keras_fashion_mnist_neural_net/Slide2.PNG -------------------------------------------------------------------------------- /DeepLearningML/1_keras_fashion_mnist_neural_net/fmnist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DeepLearningML/1_keras_fashion_mnist_neural_net/fmnist.png -------------------------------------------------------------------------------- /ML/1_linear_reg/areas.csv: -------------------------------------------------------------------------------- 1 | area 2 | 1000 3 | 1500 4 | 2300 5 | 3540 6 | 4120 7 | 4560 8 | 5490 9 | 3460 10 | 4750 11 | 2300 12 | 9000 13 | 8600 14 | 7100 15 | -------------------------------------------------------------------------------- /Basics/Hindi/10_name_/utility.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | print("In utility.py ==> foo()") 3 | 4 | if __name__=='__main__': 5 | foo() 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Basics/test.py: -------------------------------------------------------------------------------- 1 | def sum(a,b): 2 | return a+b 3 | 4 | n1=int(input('enter first number: ')) 5 | n2=int(input('enter first number: ')) 6 | print('sum is: ',sum(n1,n2)) 7 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/model/rajaji_nagar_outliers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataScience/BangloreHomePrices/model/rajaji_nagar_outliers.png -------------------------------------------------------------------------------- /TechTopics/ResumeDataAnalyst/Resume_data_analyst_fresher.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/TechTopics/ResumeDataAnalyst/Resume_data_analyst_fresher.pdf -------------------------------------------------------------------------------- /pandas/3_different_ways_of_creating_dataframe/weather_data.csv: -------------------------------------------------------------------------------- 1 | day,temperature,windspeed,event 2 | 1/1/2017,32,6,Rain 3 | 1/2/2017,35,7,Sunny 4 | 1/3/2017,28,2,Snow 5 | -------------------------------------------------------------------------------- /pandas/5_handling_missing_data_fillna_dropna_interpolate/missing_data.txt: -------------------------------------------------------------------------------- 1 | http://pandas.pydata.org/pandas-docs/version/0.15.2/10min.html 2 | 3 | check missing data section -------------------------------------------------------------------------------- /DeepLearningML/1_keras_fashion_mnist_neural_net/classlabels.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DeepLearningML/1_keras_fashion_mnist_neural_net/classlabels.JPG -------------------------------------------------------------------------------- /TechTopics/HowToLearnProgramming/11_steps_learn_programming.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/TechTopics/HowToLearnProgramming/11_steps_learn_programming.png -------------------------------------------------------------------------------- /TechTopics/HowToLearnProgramming/nishant_effective_learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/TechTopics/HowToLearnProgramming/nishant_effective_learning.png -------------------------------------------------------------------------------- /TechTopics/ResumeDataAnalyst/Resume_data_analyst_experienced.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/TechTopics/ResumeDataAnalyst/Resume_data_analyst_experienced.pdf -------------------------------------------------------------------------------- /pandas/3_different_ways_of_creating_dataframe/weather_data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/3_different_ways_of_creating_dataframe/weather_data.xlsx -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/read_write_with_flask/example2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/4_read_write_to_excel/read_write_with_flask/example2.xlsx -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/funny.txt: -------------------------------------------------------------------------------- 1 | Teacher: Why are you late, raghu? 2 | Raghu: Because of the sign 3 | Teacher: What sign? 4 | Raghu: The one that says "School Ahead, Go slow" -------------------------------------------------------------------------------- /Basics/Hindi/9_modules/main.py: -------------------------------------------------------------------------------- 1 | # import sys 2 | # sys.path.append("C:\\Code\\modules") 3 | 4 | from utility import area 5 | 6 | print(area.area_circle(3)) 7 | print(area.area_square(3)) -------------------------------------------------------------------------------- /Basics/Hindi/9_modules/utility/area.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def area_circle(radius): 4 | return math.pi*(radius**2) 5 | 6 | def area_square(length): 7 | return length**2 8 | 9 | -------------------------------------------------------------------------------- /Basics/myprogram.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("C:\Code") 3 | import functions as f 4 | area = f.calculate_square_area(10) 5 | area = f.calculate_triangle_area(5,10) 6 | print(area) -------------------------------------------------------------------------------- /unittesting_pytest/custom_markers/mathlib.py: -------------------------------------------------------------------------------- 1 | def calc_total(a,b): 2 | return a+b 3 | 4 | def calc_multiply(a,b): 5 | return a*b 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/model/banglore_home_prices_model.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataScience/BangloreHomePrices/model/banglore_home_prices_model.pickle -------------------------------------------------------------------------------- /DeepLearningML/1_keras_fashion_mnist_neural_net/fashion_neural_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DeepLearningML/1_keras_fashion_mnist_neural_net/fashion_neural_net.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/homeprices.csv: -------------------------------------------------------------------------------- 1 | area,bedrooms,age,price 2 | 2600,3,20,550000 3 | 3000,4,15,565000 4 | 3200,,18,610000 5 | 3600,3,30,595000 6 | 4000,5,8,760000 7 | 4100,6,8,810000 8 | -------------------------------------------------------------------------------- /pandas/5_handling_missing_data_fillna_dropna_interpolate/weather_data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/pandas/5_handling_missing_data_fillna_dropna_interpolate/weather_data.xls -------------------------------------------------------------------------------- /pandas/11_melt/weather.csv: -------------------------------------------------------------------------------- 1 | day,chicago,chennai,berlin 2 | Monday,32,75,41 3 | Tuesday,30,77,43 4 | Wednesday,28,75,45 5 | Thursday,22,82,38 6 | Friday,30,83,30 7 | Saturday,20,81,45 8 | Sunday,25,77,47 9 | -------------------------------------------------------------------------------- /pandas/18_ts_period/wmt.csv: -------------------------------------------------------------------------------- 1 | Line Item,2017Q1,2017Q2,2017Q3,2017Q4,2018Q1 2 | Revenue,115904,120854,118179,130936,117542 3 | Expenses,86544,89485,87484,97743,87688 4 | Profit,29360,31369,30695,33193,29854 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/server/artifacts/banglore_home_prices_model.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalsays/py/HEAD/DataScience/BangloreHomePrices/server/artifacts/banglore_home_prices_model.pickle -------------------------------------------------------------------------------- /Basics/22_Generators.py: -------------------------------------------------------------------------------- 1 | def fib(): 2 | a, b = 0, 1 3 | while True: 4 | yield a 5 | a, b = b, a+b 6 | 7 | for f in fib(): 8 | if f > 100: 9 | break 10 | print(f) 11 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/Exercise/output.csv: -------------------------------------------------------------------------------- 1 | Company Name,PE Ratio, PB Ratio 2 | Reliance,22.23,2.25 3 | Tata Steel,4.39,0.68 4 | Infosys,18.57,4.42 5 | Axis Bank,38.89,2.81 6 | Bajaj Finance,58.61,11.86 7 | -------------------------------------------------------------------------------- /pandas/21_sql/customers.csv: -------------------------------------------------------------------------------- 1 | Customer Name,Customer Phone 2 | rafael nadal,4567895647 3 | maria sharapova,434534545 4 | vladimir putin,89345345 5 | kim un jong,123434456 6 | jeff bezos,934534543 7 | rahul gandhi,44324222 8 | -------------------------------------------------------------------------------- /DataStructures/4_HashTable_2_Collisions/Solution/nyc_weather.csv: -------------------------------------------------------------------------------- 1 | date,temperature(F) 2 | Jan 1,27 3 | Jan 2,31 4 | Jan 3,23 5 | Jan 4,34 6 | Jan 5,37 7 | Jan 6,38 8 | Jan 7,29 9 | Jan 8,30 10 | Jan 9,35 11 | Jan 10,30 -------------------------------------------------------------------------------- /ML/3_gradient_descent/Exercise/test_scores.csv: -------------------------------------------------------------------------------- 1 | name,math,cs 2 | david,92,98 3 | laura,56,68 4 | sanjay,88,81 5 | wei,70,80 6 | jeff,80,83 7 | aamir,49,52 8 | venkat,65,66 9 | virat,35,30 10 | arthur,66,68 11 | paul,67,73 -------------------------------------------------------------------------------- /pandas/2_dataframe_basics/weather_data.csv: -------------------------------------------------------------------------------- 1 | day,temperature,windspeed,event 2 | 1/1/2017,32,6,Rain 3 | 1/2/2017,35,7,Sunny 4 | 1/3/2017,28,2,Snow 5 | 1/4/2017,24,7,Snow 6 | 1/5/2017,32,4,Rain 7 | 1/6/2017,31,2,Sunny 8 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/Exercise/stocks.csv: -------------------------------------------------------------------------------- 1 | Company Name,Price,Earnings Per Share, Book Value 2 | Reliance,1467,66,653 3 | Tata Steel,391,89,572 4 | Infosys,650,35,147 5 | Axis Bank,739,19,263 6 | Bajaj Finance,4044,69,341 -------------------------------------------------------------------------------- /pandas/10_pivot/weather3.csv: -------------------------------------------------------------------------------- 1 | date,city,temperature,humidity 2 | 5/1/2017,new york,65,56 3 | 5/2/2017,new york,61,54 4 | 5/3/2017,new york,70,60 5 | 12/1/2017,new york,30,50 6 | 12/2/2017,new york,28,52 7 | 12/3/2017,new york,25,51 8 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/scores.csv: -------------------------------------------------------------------------------- 1 | rohit,9 2 | shakib,56 3 | babar,56 4 | rohit,120 5 | rohit,105 6 | shakib,78 7 | rohit,140 8 | babar,45 9 | rohit,130 10 | shakib,102 11 | babar,120 12 | babar,5 13 | shakib,72 14 | babar,67 -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/stock_data.csv: -------------------------------------------------------------------------------- 1 | tickers,eps,revenue,price,people 2 | GOOGL,27.82,87,845,larry page 3 | WMT,4.61,484,65,n.a. 4 | MSFT,-1,85,64,bill gates 5 | RIL ,not available,50,1023,mukesh ambani 6 | TATA,5.6,-1,n.a.,ratan tata 7 | -------------------------------------------------------------------------------- /Basics/area.py: -------------------------------------------------------------------------------- 1 | def calculate_area(base, height): 2 | print("__name__: ",__name__) 3 | return 1/2*(base*height) 4 | 5 | if __name__ == "__main__": 6 | print("I am in area.py") 7 | a=calculate_area(10, 20) 8 | print("area: ",a) 9 | -------------------------------------------------------------------------------- /pandas/20_shift_lag/fb.csv: -------------------------------------------------------------------------------- 1 | Date,Price 2 | 15-Aug-17,171 3 | 16-Aug-17,170 4 | 17-Aug-17,166.91 5 | 18-Aug-17,167.41 6 | 21-Aug-17,167.78 7 | 22-Aug-17,169.64 8 | 23-Aug-17,168.71 9 | 24-Aug-17,167.74 10 | 25-Aug-17,166.32 11 | 28-Aug-17,167.24 12 | -------------------------------------------------------------------------------- /DataStructures/2_Arrays/Solution/3_odd_even_numbers.py: -------------------------------------------------------------------------------- 1 | max = int(input("Enter max number: ")) 2 | 3 | odd_numbers = [] 4 | 5 | for i in range(max): 6 | if i%2 == 1: 7 | odd_numbers.append(i) 8 | 9 | print("Odd numbers: ",odd_numbers) 10 | -------------------------------------------------------------------------------- /Modules/urllib_demo.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | with urlopen('http://www.agilemanifesto.org/') as response: 3 | for line in response: 4 | line = line.decode('utf-8') # Decoding the binary data to text. 5 | print(line) 6 | -------------------------------------------------------------------------------- /Basics/word_occurences.py: -------------------------------------------------------------------------------- 1 | s = "I work in bloomberg founded by bloomberg work work" 2 | 3 | tokens = s.split(" ") 4 | d = {} 5 | for token in tokens: 6 | if token in d: 7 | d[token] += 1 8 | else: 9 | d[token] = 1 10 | 11 | print(d) -------------------------------------------------------------------------------- /pandas/6_handling_missing_data_replace/weather_data.csv: -------------------------------------------------------------------------------- 1 | day,temperature,windspeed,event 2 | 1/1/2017,32,6,Rain 3 | 1/2/2017,-99999,7,Sunny 4 | 1/3/2017,28,-99999,Snow 5 | 1/4/2017,-99999,7,0 6 | 1/5/2017,32,-99999,Rain 7 | 1/6/2017,31,2,Sunny 8 | 1/6/2017,34,5,0 9 | -------------------------------------------------------------------------------- /Debugging/debugging.py: -------------------------------------------------------------------------------- 1 | def add_num(a,b): 2 | '''Return sum of two numbers''' 3 | s=a+b 4 | return s 5 | 6 | n1=input('enter first number:') 7 | n1=int(n1) 8 | n2=input('enter second number:') 9 | n2=int(n2) 10 | s = add_num(n1,n2) 11 | print ('sum is: ',s); -------------------------------------------------------------------------------- /pandas/19_ts_timezone/msft.csv: -------------------------------------------------------------------------------- 1 | "Microsoft Stock Price: 17 August, 2017", 2 | Date Time,Price 3 | 8/17/2017 9:00:00 AM,72.38 4 | 8/17/2017 9:15:00 AM,71 5 | 8/17/2017 9:30:00 AM,71.67 6 | 8/17/2017 10:00:00 AM,72.8 7 | 8/17/2017 10:30:00 AM,73 8 | 8/17/2017 11:00:00 AM,72.5 9 | -------------------------------------------------------------------------------- /ML/2_linear_reg_multivariate/Exercise/hiring.csv: -------------------------------------------------------------------------------- 1 | experience,test_score(out of 10),interview_score(out of 10),salary($) 2 | ,8,9,50000 3 | ,8,6,45000 4 | five,6,7,60000 5 | two,10,10,65000 6 | seven,9,6,70000 7 | three,7,10,62000 8 | ten,,7,72000 9 | eleven,7,8,80000 10 | -------------------------------------------------------------------------------- /Multiprocessing/multiprocessing_pool.py: -------------------------------------------------------------------------------- 1 | from multiprocessing import Pool 2 | 3 | 4 | def f(n): 5 | return n*n 6 | 7 | if __name__ == "__main__": 8 | p = Pool(processes=3) 9 | result = p.map(f,[1,2,3,4,5]) 10 | for n in result: 11 | print(n) 12 | -------------------------------------------------------------------------------- /pandas/10_pivot/weather2.csv: -------------------------------------------------------------------------------- 1 | date,city,temperature,humidity 2 | 5/1/2017,new york,65,56 3 | 5/1/2017,new york,61,54 4 | 5/2/2017,new york,70,60 5 | 5/2/2017,new york,72,62 6 | 5/1/2017,mumbai,75,80 7 | 5/1/2017,mumbai,78,83 8 | 5/2/2017,mumbai,82,85 9 | 5/2/2017,mumbai,80,26 10 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/nginx_files/bhp.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | server_name bhp; 5 | 6 | root /home/ubuntu/BangloreHomePrices/client; 7 | index app.html; 8 | 9 | location /api/ { 10 | rewrite ^/api(.*) $1 break; 11 | proxy_pass http://127.0.0.1:5000; 12 | } 13 | } -------------------------------------------------------------------------------- /pandas/10_pivot/weather.csv: -------------------------------------------------------------------------------- 1 | date,city,temperature,humidity 2 | 5/1/2017,new york,65,56 3 | 5/2/2017,new york,66,58 4 | 5/3/2017,new york,68,60 5 | 5/1/2017,mumbai,75,80 6 | 5/2/2017,mumbai,78,83 7 | 5/3/2017,mumbai,82,85 8 | 5/1/2017,beijing,80,26 9 | 5/2/2017,beijing,77,30 10 | 5/3/2017,beijing,79,35 11 | -------------------------------------------------------------------------------- /pandas/5_handling_missing_data_fillna_dropna_interpolate/weather_data.csv: -------------------------------------------------------------------------------- 1 | day,temperature,windspeed,event 2 | 1/1/2017,32,6,Rain 3 | 1/4/2017,,9,Sunny 4 | 1/5/2017,28,,Snow 5 | 1/6/2017,,7, 6 | 1/7/2017,32,,Rain 7 | 1/8/2017,,,Sunny 8 | 1/9/2017,,, 9 | 1/10/2017,34,8,Cloudy 10 | 1/11/2017,40,12,Sunny 11 | -------------------------------------------------------------------------------- /Basics/20_raise_exception.py: -------------------------------------------------------------------------------- 1 | def process_file(): 2 | try: 3 | f=open("c:\\code\\data.txt") 4 | x=1/0 5 | except FileNotFoundError as e: 6 | print("inside except") 7 | finally: 8 | print("cleaning up file") 9 | f.close() 10 | 11 | 12 | 13 | 14 | process_file() 15 | 16 | -------------------------------------------------------------------------------- /ML/7_logistic_reg/insurance_data.csv: -------------------------------------------------------------------------------- 1 | age,bought_insurance 2 | 22,0 3 | 25,0 4 | 47,1 5 | 52,0 6 | 46,1 7 | 56,1 8 | 55,0 9 | 60,1 10 | 62,1 11 | 61,1 12 | 18,0 13 | 28,0 14 | 27,0 15 | 29,0 16 | 49,1 17 | 55,1 18 | 25,1 19 | 58,1 20 | 19,0 21 | 18,0 22 | 21,0 23 | 26,0 24 | 40,1 25 | 45,1 26 | 50,1 27 | 54,1 28 | 23,0 -------------------------------------------------------------------------------- /Basics/16_exception.py: -------------------------------------------------------------------------------- 1 | x=input("Enter number1: ") 2 | y=input("Enter number2: ") 3 | try: 4 | z = int(x) / int(y) 5 | except ZeroDivisionError as e: 6 | print('Division by zero exception') 7 | z = None 8 | except TypeError as e: 9 | print('Type error exception') 10 | z = None 11 | print("Division is: ", z) -------------------------------------------------------------------------------- /Basics/address.py: -------------------------------------------------------------------------------- 1 | book = {} 2 | book['tom'] = { 3 | 'name': 'tom', 4 | 'address': '1 red street, NY', 5 | 'phone': 98989898 6 | } 7 | book['bob'] = { 8 | 'name': 'bob', 9 | 'address': '1 green street, NY', 10 | 'phone': 23424234 11 | } 12 | 13 | import json 14 | s=json.dumps(book) 15 | with open("c://data//book.txt","w") as f: 16 | f.write(s) -------------------------------------------------------------------------------- /unittesting_pytest/custom_markers/test_mathlib.py: -------------------------------------------------------------------------------- 1 | import mathlib 2 | import pytest 3 | 4 | @pytest.mark.windows 5 | def test_windows_1(): 6 | assert True 7 | 8 | @pytest.mark.windows 9 | def test_windows_2(): 10 | assert True 11 | 12 | @pytest.mark.mac 13 | def test_mac_1(): 14 | assert True 15 | 16 | @pytest.mark.mac 17 | def test_mac_2(): 18 | assert True -------------------------------------------------------------------------------- /Basics/19_multiple_inheritance.py: -------------------------------------------------------------------------------- 1 | class Father(): 2 | def skills(self): 3 | print("gardening,programming") 4 | 5 | class Mother(): 6 | def skills(self): 7 | print("cooking,art") 8 | 9 | class Child(Father,Mother): 10 | def skills(self): 11 | Father.skills(self) 12 | Mother.skills(self) 13 | print("sports") 14 | 15 | c = Child() 16 | c.skills() 17 | -------------------------------------------------------------------------------- /Debugging/expenses.txt: -------------------------------------------------------------------------------- 1 | 1230 2 | 2240 3 | 1500 4 | 1678 5 | 2020 6 | 1580 7 | 2240 8 | 1500 9 | 1245 10 | 2300 11 | 1246 12 | 3400 13 | 1580 14 | 2240 15 | 1500 16 | 3240 17 | 2240 18 | 1500 19 | 1245 20 | 2300 21 | 1246 22 | 3400 23 | 1580 24 | 2240 25 | XYGF 26 | 1245 27 | 2300 28 | 1246 29 | 3400 30 | 1580 31 | 2240 32 | 1500 33 | 3240 34 | 2240 35 | 1500 36 | 1245 37 | 2300 38 | 1246 39 | 3400 40 | 1580 41 | 2240 -------------------------------------------------------------------------------- /ML/1_linear_reg/prediction.csv: -------------------------------------------------------------------------------- 1 | ,area,prices 2 | 0,1000,316404.1095890411 3 | 1,1500,384297.9452054794 4 | 2,2300,492928.0821917808 5 | 3,3540,661304.794520548 6 | 4,4120,740061.6438356165 7 | 5,4560,799808.2191780822 8 | 6,5490,926090.7534246575 9 | 7,3460,650441.7808219178 10 | 8,4750,825607.8767123288 11 | 9,2300,492928.0821917808 12 | 10,9000,1402705.479452055 13 | 11,8600,1348390.4109589043 14 | 12,7100,1144708.904109589 15 | -------------------------------------------------------------------------------- /Debugging/conditional_breakpoint.py: -------------------------------------------------------------------------------- 1 | expense_list = [1230, 2240, 1500, 1678, 2020, 1580, 2240, 1500, 1245, 2300, 1246, 3400, 1580, 2240, 1500, 3240, 2240, 1500, 1245, 2300, 1246, 3400, 1580, 2240, 2467, 1245, 2300, 1246, 3400, 1580, 2240, 1500, 3240, 2240, 1500, 1245, 2300, 1246, 3400, 1580, 2240] 2 | total_expense = 0 3 | for expense in expense_list: 4 | total_expense += expense 5 | 6 | print("total expense is: ", total_expense) 7 | 8 | -------------------------------------------------------------------------------- /Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_3_circle.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def circle_calc(radius): 4 | area=math.pi*(radius**2) 5 | circumference=2*math.pi*radius 6 | diameter=2*radius 7 | return area, circumference,diameter 8 | 9 | if __name__=="__main__": 10 | r=input("Enter a radius:") 11 | r=float(r) 12 | area, c, d = circle_calc(r) 13 | print(f"area {area}, circumference {c}, diameter {d}") -------------------------------------------------------------------------------- /ML/6_train_test_split/carprices.csv: -------------------------------------------------------------------------------- 1 | Mileage,Age(yrs),Sell Price($) 2 | 69000,6,18000 3 | 35000,3,34000 4 | 57000,5,26100 5 | 22500,2,40000 6 | 46000,4,31500 7 | 59000,5,26750 8 | 52000,5,32000 9 | 72000,6,19300 10 | 91000,8,12000 11 | 67000,6,22000 12 | 83000,7,18700 13 | 79000,7,19500 14 | 59000,5,26000 15 | 58780,4,27500 16 | 82450,7,19400 17 | 25400,3,35000 18 | 28000,2,35500 19 | 69000,5,19700 20 | 87600,8,12800 21 | 52000,5,28200 22 | -------------------------------------------------------------------------------- /ML/5_one_hot_encoding/homeprices.csv: -------------------------------------------------------------------------------- 1 | town,area,price 2 | monroe township,2600,550000 3 | monroe township,3000,565000 4 | monroe township,3200,610000 5 | monroe township,3600,680000 6 | monroe township,4000,725000 7 | west windsor,2600,585000 8 | west windsor,2800,615000 9 | west windsor,3300,650000 10 | west windsor,3600,710000 11 | robinsville,2600,575000 12 | robinsville,2900,600000 13 | robinsville,3100,620000 14 | robinsville,3600,695000 15 | -------------------------------------------------------------------------------- /pandas/7_group_by/weather_by_cities.csv: -------------------------------------------------------------------------------- 1 | day,city,temperature,windspeed,event 2 | 1/1/2017,new york,32,6,Rain 3 | 1/2/2017,new york,36,7,Sunny 4 | 1/3/2017,new york,28,12,Snow 5 | 1/4/2017,new york,33,7,Sunny 6 | 1/1/2017,mumbai,90,5,Sunny 7 | 1/2/2017,mumbai,85,12,Fog 8 | 1/3/2017,mumbai,87,15,Fog 9 | 1/4/2017,mumbai,92,5,Rain 10 | 1/1/2017,paris,45,20,Sunny 11 | 1/2/2017,paris,50,13,Cloudy 12 | 1/3/2017,paris,54,8,Cloudy 13 | 1/4/2017,paris,42,10,Cloudy 14 | -------------------------------------------------------------------------------- /Multiprocessing/multiprocessing_queue_pipe.py: -------------------------------------------------------------------------------- 1 | import multiprocessing 2 | 3 | def calc_square(numbers, q): 4 | for n in numbers: 5 | q.put(n*n) 6 | 7 | if __name__ == "__main__": 8 | numbers = [2,3,5] 9 | q = multiprocessing.Queue() 10 | p = multiprocessing.Process(target=calc_square, args=(numbers,q)) 11 | 12 | p.start() 13 | p.join() 14 | 15 | while q.empty() is False: 16 | print(q.get()) 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /numpy/numpy_tutorial.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import time 3 | import sys 4 | SIZE = 1000000 5 | l1 = range(SIZE) 6 | l2 = range(SIZE) 7 | a1=np.arange(SIZE) 8 | a2=np.arange(SIZE) 9 | 10 | # python list 11 | start = time.time() 12 | result = [(x+y) for x,y in zip(l1,l2)] 13 | print("python list took: ",(time.time()-start)*1000) 14 | # numpy array 15 | start= time.time() 16 | result = a1 + a2 17 | print("numpy took: ", (time.time()-start)*1000) 18 | 19 | 20 | -------------------------------------------------------------------------------- /ML/5_one_hot_encoding/Exercise/carprices.csv: -------------------------------------------------------------------------------- 1 | Car Model,Mileage,Sell Price($),Age(yrs) 2 | BMW X5,69000,18000,6 3 | BMW X5,35000,34000,3 4 | BMW X5,57000,26100,5 5 | BMW X5,22500,40000,2 6 | BMW X5,46000,31500,4 7 | Audi A5,59000,29400,5 8 | Audi A5,52000,32000,5 9 | Audi A5,72000,19300,6 10 | Audi A5,91000,12000,8 11 | Mercedez Benz C class,67000,22000,6 12 | Mercedez Benz C class,83000,20000,7 13 | Mercedez Benz C class,79000,21000,7 14 | Mercedez Benz C class,59000,33000,5 15 | -------------------------------------------------------------------------------- /Multiprocessing/multithreading_producer_consumer.py: -------------------------------------------------------------------------------- 1 | import time 2 | from random import randint 3 | import threading 4 | 5 | queue = [] 6 | 7 | def produce(): 8 | for i in range(0,5): 9 | time.sleep(1) 10 | queue.append(randint(0,9)) 11 | 12 | def consume(): 13 | while True: 14 | if len(queue) > 0: 15 | 16 | 17 | if "__name__"=="__main__": 18 | p = threading.Thread(target=produce) 19 | c = threading.Thread(target=consume) 20 | 21 | -------------------------------------------------------------------------------- /ML/13_kmeans/income.csv: -------------------------------------------------------------------------------- 1 | Name,Age,Income($) 2 | Rob,27,70000 3 | Michael,29,90000 4 | Mohan,29,61000 5 | Ismail,28,60000 6 | Kory,42,150000 7 | Gautam,39,155000 8 | David,41,160000 9 | Andrea,38,162000 10 | Brad,36,156000 11 | Angelina,35,130000 12 | Donald,37,137000 13 | Tom,26,45000 14 | Arnold,27,48000 15 | Jared,28,51000 16 | Stark,29,49500 17 | Ranbir,32,53000 18 | Dipika,40,65000 19 | Priyanka,41,63000 20 | Nick,43,64000 21 | Alia,39,80000 22 | Sid,41,82000 23 | Abdul,39,58000 24 | 25 | 26 | -------------------------------------------------------------------------------- /ML/14_naive_bayes/exercise.md: -------------------------------------------------------------------------------- 1 | ### Machine Learning Tutorial - Naive Bayes: Exercise 2 | 3 | Use wine dataset from sklearn.datasets to classify wines into 3 categories. Load the dataset and split it into test and train. After that train the model using Gaussian and Multinominal classifier and post which model performs better. Use the trained model to perform some predictions on test data. 4 | 5 | [Solution](https://github.com/codebasics/py/blob/master/ML/14_naive_bayes/Exercise/14_naive_bayes_exercise.ipynb) -------------------------------------------------------------------------------- /Multiprocessing/multiprocessing_value_array.py: -------------------------------------------------------------------------------- 1 | import multiprocessing 2 | 3 | def calc_square(numbers, result, v): 4 | v.value = 5.67 5 | for idx, n in enumerate(numbers): 6 | result[idx] = n*n 7 | 8 | if __name__ == "__main__": 9 | numbers = [2,3,5] 10 | result = multiprocessing.Array('i',3) 11 | v = multiprocessing.Value('d', 0.0) 12 | p = multiprocessing.Process(target=calc_square, args=(numbers, result, v)) 13 | 14 | p.start() 15 | p.join() 16 | 17 | print(v.value) -------------------------------------------------------------------------------- /unittesting_pytest/parametrize/test_mathlib.py: -------------------------------------------------------------------------------- 1 | import mathlib 2 | import pytest 3 | 4 | @pytest.mark.parametrize("test_input, expected_output", 5 | [ 6 | (5, 25), 7 | (9, 81), 8 | (10, 100) 9 | ] 10 | ) 11 | def test_calc_square(test_input, expected_output): 12 | result = mathlib.calc_square(test_input) 13 | assert result == expected_output 14 | 15 | -------------------------------------------------------------------------------- /.idea/py.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /Modules/pandas_tutorial.py: -------------------------------------------------------------------------------- 1 | """ 2 | Introducing pandas using namespace pd, 3 | such that you can call pandas class using pd instead of pandas. 4 | """ 5 | 6 | import pandas as pd 7 | 8 | # Dict object, with arbitrary data. 9 | stats = { 10 | 'Month': ['Jan', 'Feb', 'March', 'April'], 11 | 'Expenses': [2350, 3400, 2700, 2200], 12 | 'Income': [4000, 4000, 4000, 4000] 13 | } 14 | 15 | # stats is now a pandas data frame object. 16 | df = pd.DataFrame(stats) 17 | # df = df.set_index('Month') 18 | print(df.Month) 19 | -------------------------------------------------------------------------------- /Basics/Hindi/4_user_input/4_user_input_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python User Input 2 | 3 | 1. Write a program that can find area of a triangle. It should take base and height as 4 | an input from user and using that it should print an area of a triangle 5 | 2. Write a program that takes file name with extension as an input and 6 | prints just the file name without extension (you can assume that file extensions 7 | are always 3 character long) 8 | 9 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/4_user_input/Exercise/4_user_input_exercise.py) -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py: -------------------------------------------------------------------------------- 1 | with open("stocks.csv","r") as f, open("output.csv","w") as out: 2 | out.write("Company Name,PE Ratio, PB Ratio\n") 3 | next(f) # This will skip first line in the file which is a header 4 | for line in f: 5 | tokens=line.split(',') 6 | stock = tokens[0] 7 | price = float(tokens[1]) 8 | eps = float(tokens[2]) 9 | book = float(tokens[3]) 10 | pe = round(price/eps,2) 11 | pb = round(price/book,2) 12 | out.write(f"{stock},{pe},{pb}\n") 13 | -------------------------------------------------------------------------------- /Basics/21_iterators.py: -------------------------------------------------------------------------------- 1 | class RemoteControl(): 2 | def __init__(self): 3 | self.channels = ["HBO","cnn","abc","espn"] 4 | self.index = -1 5 | 6 | def __iter__(self): 7 | return self 8 | 9 | def __next__(self): 10 | self.index += 1 11 | if self.index == len(self.channels): 12 | raise StopIteration 13 | 14 | return self.channels[self.index] 15 | 16 | r = RemoteControl() 17 | itr=iter(r) 18 | print(next(itr)) 19 | print(next(itr)) 20 | print(next(itr)) 21 | print(next(itr)) 22 | print(next(itr)) 23 | 24 | 25 | -------------------------------------------------------------------------------- /Multiprocessing/multiprocessing_introduction.py: -------------------------------------------------------------------------------- 1 | import time 2 | import multiprocessing 3 | 4 | def calc_square(numbers): 5 | for n in numbers: 6 | print('square ' + str(n*n)) 7 | 8 | def calc_cube(numbers): 9 | for n in numbers: 10 | print('cube ' + str(n*n*n)) 11 | 12 | if __name__ == "__main__": 13 | arr = [2,3,8] 14 | p1 = multiprocessing.Process(target=calc_square, args=(arr,)) 15 | p2 = multiprocessing.Process(target=calc_cube, args=(arr,)) 16 | 17 | p1.start() 18 | p2.start() 19 | 20 | p1.join() 21 | p2.join() 22 | 23 | print("Done!") -------------------------------------------------------------------------------- /Basics/17_class.py: -------------------------------------------------------------------------------- 1 | class Human: 2 | def __init__(self, n, o): 3 | self.name = n 4 | self.occupation = o 5 | 6 | def do_work(self): 7 | if self.occupation == "tennis player": 8 | print(self.name, "plays tennis") 9 | elif self.occupation == "actor": 10 | print(self.name, "shoots film") 11 | 12 | def speaks(self): 13 | print(self.name, "says how are you?") 14 | 15 | tom = Human("tom cruise","actor") 16 | tom.do_work() 17 | tom.speaks() 18 | 19 | maria = Human("maria sharapova","tennis player") 20 | maria.do_work() 21 | maria.speaks() -------------------------------------------------------------------------------- /unittesting_pytest/fixtures/test_mydb.py: -------------------------------------------------------------------------------- 1 | from fixtures.mydb import MyDB 2 | 3 | import pytest 4 | 5 | @pytest.fixture(scope="module") 6 | def cur(): 7 | print("setting up") 8 | db = MyDB() 9 | conn = db.connect("server") 10 | curs = conn.cursor() 11 | yield curs 12 | curs.close() 13 | conn.close() 14 | print("closing DB") 15 | 16 | def test_johns_id(cur): 17 | id = cur.execute("select id from employee_db where name=John") 18 | assert id == 123 19 | 20 | def test_toms_id(cur): 21 | id = cur.execute("select id from employee_db where name=Tom") 22 | assert id == 789 23 | -------------------------------------------------------------------------------- /pandas/16_ts_holidays/aapl_no_dates.csv: -------------------------------------------------------------------------------- 1 | Open,High,Low,Close,Volume 2 | 144.88,145.3,143.1,143.5,14277848 3 | 143.69,144.79,142.72,144.09,21569557 4 | 143.02,143.5,142.41,142.73,24128782 5 | 142.9,144.75,142.9,144.18,19201712 6 | 144.11,145.95,143.37,145.06,21090636 7 | 144.73,145.85,144.38,145.53,19781836 8 | 145.87,146.18,144.82,145.74,24884478 9 | 145.5,148.49,145.44,147.77,25199373 10 | 147.97,149.33,147.33,149.04,20132061 11 | 148.82,150.9,148.57,149.56,23793456 12 | 149.2,150.13,148.67,150.08,17868792 13 | 150.48,151.42,149.95,151.02,20922969 14 | 151.5,151.74,150.19,150.34,17243748 15 | 149.99,150.44,148.88,150.27,26252630 16 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/Exercise/exercise_1_poem.py: -------------------------------------------------------------------------------- 1 | word_stats={} 2 | 3 | with open("poem.txt","r") as f: 4 | for line in f: 5 | words=line.split(' ') 6 | for word in words: 7 | if word in word_stats: 8 | word_stats[word]+=1 9 | else: 10 | word_stats[word] = 1 11 | 12 | print(word_stats) 13 | 14 | word_occurances = list(word_stats.values()) 15 | max_count = max(word_occurances) 16 | print("Max occurances of any word is:",max_count) 17 | 18 | print("Words with max occurances are: ") 19 | for word, count in word_stats.items(): 20 | if count==max_count: 21 | print(word) -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/read_write_excel_file.txt: -------------------------------------------------------------------------------- 1 | df_stocks = pd.DataFrame({ 2 | 'tickers': ['GOOGL', 'WMT', 'MSFT'], 3 | 'price': [845, 65, 64 ], 4 | 'pe': [30.37, 14.26, 30.97], 5 | 'eps': [27.82, 4.61, 2.12] 6 | }) 7 | 8 | df_weather = pd.DataFrame({ 9 | 'day': ['1/1/2017','1/2/2017','1/3/2017'], 10 | 'temperature': [32,35,28], 11 | 'event': ['Rain', 'Sunny', 'Snow'] 12 | }) 13 | 14 | with pd.ExcelWriter('stocks_weather.xlsx') as writer: 15 | df_stocks.to_excel(writer, sheet_name="stocks") 16 | df_weather.to_excel(writer, sheet_name="weather") 17 | 18 | ExcelWriter documentation: http://xlsxwriter.readthedocs.io/working_with_pandas.html -------------------------------------------------------------------------------- /ML/15_gridsearch/exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Machine Learning Finding Optimal Model and Hyperparameters 2 | 3 | For digits dataset in sklearn.dataset, please try following classifiers and find out the one that gives best performance. Also find the optimal parameters for that classifier. 4 | 5 | ``` 6 | from sklearn import svm 7 | from sklearn.ensemble import RandomForestClassifier 8 | from sklearn.linear_model import LogisticRegression 9 | from sklearn.naive_bayes import GaussianNB 10 | from sklearn.naive_bayes import MultinomialNB 11 | from sklearn.tree import DecisionTreeClassifier 12 | ``` 13 | 14 | [Solution](https://github.com/codebasics/py/blob/master/ML/15_gridsearch/Exercise/15_grid_search_cv_exercise.ipynb) -------------------------------------------------------------------------------- /ML/3_gradient_descent/gradient_descent.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def gradient_descent(x,y): 4 | m_curr = b_curr = 0 5 | iterations = 10000 6 | n = len(x) 7 | learning_rate = 0.08 8 | 9 | for i in range(iterations): 10 | y_predicted = m_curr * x + b_curr 11 | cost = (1/n) * sum([val**2 for val in (y-y_predicted)]) 12 | md = -(2/n)*sum(x*(y-y_predicted)) 13 | bd = -(2/n)*sum(y-y_predicted) 14 | m_curr = m_curr - learning_rate * md 15 | b_curr = b_curr - learning_rate * bd 16 | print ("m {}, b {}, cost {} iteration {}".format(m_curr,b_curr,cost, i)) 17 | 18 | x = np.array([1,2,3,4,5]) 19 | y = np.array([5,7,9,11,13]) 20 | 21 | gradient_descent(x,y) -------------------------------------------------------------------------------- /Basics/Hindi/6_if/Exercise/6_exercise2.py: -------------------------------------------------------------------------------- 1 | ## Exercise: Python If Condition 2 | # 2. Write a python program that can tell you if your sugar is normal or not. Normal fasting level sugar range is 80 to 100. 3 | # 1. Ask user to enter his fasting sugar level 4 | # 2. If it is below 80 to 100 range then print that sugar is low 5 | # 3. If it is above 100 then print that it is high otherwise print that it is normal 6 | sugar=input("Please enter your fasting sugar level:") 7 | sugar=float(sugar) 8 | if sugar<80: 9 | print("Your sugar is low, go eat some jalebi :)") 10 | elif sugar>100: 11 | print("Your sugar is high, stop eating all mithais..!") 12 | else: 13 | print("Your sugar is normal, relax and enjoy your life!") -------------------------------------------------------------------------------- /ML/9_decision_tree/salaries.csv: -------------------------------------------------------------------------------- 1 | company,job,degree,salary_more_then_100k 2 | google,sales executive,bachelors,0 3 | google,sales executive,masters,0 4 | google,business manager,bachelors,1 5 | google,business manager,masters,1 6 | google,computer programmer,bachelors,0 7 | google,computer programmer,masters,1 8 | abc pharma,sales executive,masters,0 9 | abc pharma,computer programmer,bachelors,0 10 | abc pharma,business manager,bachelors,0 11 | abc pharma,business manager,masters,1 12 | facebook,sales executive,bachelors,1 13 | facebook,sales executive,masters,1 14 | facebook,business manager,bachelors,1 15 | facebook,business manager,masters,1 16 | facebook,computer programmer,bachelors,1 17 | facebook,computer programmer,masters,1 -------------------------------------------------------------------------------- /jupyter/pandas_tutorial_on_stock_price.py: -------------------------------------------------------------------------------- 1 | # Pandas Tutorial On Stock Price Analysis 2 | 3 | # This tutorial will cover how to retrieve stock price from google finance using pandas data reader. The analysis of stock is done by plotting its high, low, close, volumne values in table and a chart. Charts are of two types, 4 | # 5 | # 1. Line Chart 6 | # 2. Bar Chart 7 | # 8 | # If you don't know what is stock then first **watch this video to gain understanding on fundamentals of stocks and investing**, 9 | # https://www.youtube.com/embed/XRO6lEu9-5w 10 | 11 | import pandas.io.data as web 12 | df = web.DataReader('AAPL', 'google', '2016/1/1', '2017/1/1') 13 | df.head() 14 | df.plot(y='Close', color="Green") 15 | df.plot.bar(y='Volume') 16 | 17 | -------------------------------------------------------------------------------- /Basics/14_json_addressbook.py: -------------------------------------------------------------------------------- 1 | import json 2 | f = open("C:\\data\\book.txt","w+") 3 | phone_book = {} 4 | command = "" 5 | while command != 'exit': 6 | command = input('Enter a command(options: new,get,save): ') 7 | if command == "new": 8 | name = input('Enter name of the person') 9 | p = input('Phone number: ') 10 | a = input('Address: ') 11 | phone_book[name] = {'phone': p, 'address': a} 12 | elif command == 'get': 13 | name = input('Enter name of the person') 14 | if name in phone_book: 15 | print(phone_book[name]) 16 | else: 17 | print('person not found in address book') 18 | elif command == 'save': 19 | f.write(json.dumps(phone_book)) 20 | -------------------------------------------------------------------------------- /Multiprocessing/multthreading_introduction.py: -------------------------------------------------------------------------------- 1 | import time 2 | import threading 3 | 4 | def calc_square(numbers): 5 | print("calculate square numbers") 6 | for n in numbers: 7 | time.sleep(1) 8 | print('square:',n*n) 9 | 10 | def calc_cube(numbers): 11 | print("calculate cube of numbers") 12 | for n in numbers: 13 | time.sleep(1) 14 | print('cube:',n*n*n) 15 | 16 | arr = [2,3,8,9] 17 | 18 | t = time.time() 19 | 20 | t1= threading.Thread(target=calc_square, args=(arr,)) 21 | t2= threading.Thread(target=calc_cube, args=(arr,)) 22 | 23 | t1.start() 24 | t2.start() 25 | 26 | t1.join() 27 | t2.join() 28 | 29 | print("done in : ",time.time()-t) 30 | print("Hah... I am done with all my work now!") 31 | -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/read_write_with_flask/static/style.css: -------------------------------------------------------------------------------- 1 | body { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;} 2 | a, h1, h2 { color: #377ba8; } 3 | h1, h2 { margin: 0; } 4 | h1 { border-bottom: 2px solid #eee; } 5 | h2 { font-size: 1.2em; } 6 | 7 | table.dataframe, .dataframe th, .dataframe td { 8 | border: none; 9 | border-bottom: 1px solid #C8C8C8; 10 | border-collapse: collapse; 11 | text-align:left; 12 | padding: 10px; 13 | margin-bottom: 40px; 14 | font-size: 0.9em; 15 | } 16 | 17 | 18 | 19 | tr:nth-child(odd) { background-color:#eee; } 20 | tr:nth-child(even) { background-color:#fff; } 21 | 22 | tr:hover { background-color: #ffff99;} 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pandas/16_ts_holidays/aapl.csv: -------------------------------------------------------------------------------- 1 | Date,Open,High,Low,Close,Volume 2 | 3-Jul-17,144.88,145.3,143.1,143.5,14277848 3 | 5-Jul-17,143.69,144.79,142.72,144.09,21569557 4 | 6-Jul-17,143.02,143.5,142.41,142.73,24128782 5 | 7-Jul-17,142.9,144.75,142.9,144.18,19201712 6 | 10-Jul-17,144.11,145.95,143.37,145.06,21090636 7 | 11-Jul-17,144.73,145.85,144.38,145.53,19781836 8 | 12-Jul-17,145.87,146.18,144.82,145.74,24884478 9 | 13-Jul-17,145.5,148.49,145.44,147.77,25199373 10 | 14-Jul-17,147.97,149.33,147.33,149.04,20132061 11 | 17-Jul-17,148.82,150.9,148.57,149.56,23793456 12 | 18-Jul-17,149.2,150.13,148.67,150.08,17868792 13 | 19-Jul-17,150.48,151.42,149.95,151.02,20922969 14 | 20-Jul-17,151.5,151.74,150.19,150.34,17243748 15 | 21-Jul-17,149.99,150.44,148.88,150.27,26252630 16 | -------------------------------------------------------------------------------- /Basics/Hindi/4_user_input/Exercise/4_user_input_exercise.py: -------------------------------------------------------------------------------- 1 | # 1. Write a program that can find area of a triangle. It should take base and height as 2 | # an input from user and using that it should print an area of a triangle 3 | print("This program helps you calculate an area of a triangle") 4 | base=input("Enter base:") 5 | height=input("Enter height:") 6 | area=(1/2)*float(base)*float(height) 7 | print("Area of a triangle is:",area) 8 | # 2. Write a program that takes file name with extension as an input and 9 | # prints just the file name without extension (you can assume that file extensions 10 | # are always 3 character long) 11 | 12 | file_name = input("Enter a file name with extension:") 13 | print("File name without extension:",file_name[:len(file_name)-4]) -------------------------------------------------------------------------------- /Advanced/decorators.py: -------------------------------------------------------------------------------- 1 | import time 2 | def time_it(func): 3 | def wrapper(*args, **kwargs): 4 | start = time.time() 5 | result = func(*args,**kwargs) 6 | end = time.time() 7 | print(func.__name__ +" took " + str((end-start)*1000) + "mil sec") 8 | return result 9 | return wrapper 10 | 11 | @time_it 12 | def calc_square(numbers): 13 | result = [] 14 | for number in numbers: 15 | result.append(number*number) 16 | return result 17 | 18 | @time_it 19 | def calc_cube(numbers): 20 | result = [] 21 | for number in numbers: 22 | result.append(number*number*number) 23 | return result 24 | 25 | array = range(1,100000) 26 | out_square = calc_square(array) 27 | out_cube = calc_cube(array) 28 | -------------------------------------------------------------------------------- /unittesting_pytest/fixtures/mydb.py: -------------------------------------------------------------------------------- 1 | class MyDB: 2 | def __init__(self): 3 | self.connection = Connection() 4 | 5 | def connect(self, connection_string): 6 | return self.connection 7 | 8 | class Connection: 9 | def __init__(self): 10 | self.cur = Cursor() 11 | 12 | def cursor(self): 13 | return self.cur 14 | 15 | def close(self): 16 | pass 17 | 18 | class Cursor(): 19 | def execute(self, query): 20 | if query == "select id from employee_db where name=John": 21 | return 123 22 | elif query == "select id from employee_db where name=Tom": 23 | return 789 24 | else: 25 | return -1 26 | 27 | def close(self): 28 | pass 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Basics/18_inheritance.py: -------------------------------------------------------------------------------- 1 | class Vehicle: 2 | def general_usage(self): 3 | print("general use: transporation") 4 | 5 | class Car(Vehicle): 6 | def __init__(self): 7 | print("I'm car") 8 | self.wheels = 4 9 | self.has_roof = True 10 | 11 | def specific_usage(self): 12 | self.general_usage() 13 | print("specific use: commute to work, vacation with family") 14 | 15 | class MotorCycle(Vehicle): 16 | def __init__(self): 17 | print("I'm motor cycle") 18 | self.wheels = 2 19 | self.has_roof = False 20 | 21 | def specific_usage(self): 22 | self.general_usage() 23 | print("specific use: road trip, racing") 24 | 25 | c = Car() 26 | m = MotorCycle() 27 | 28 | print(issubclass(Car,MotorCycle)) -------------------------------------------------------------------------------- /Basics/Hindi/1_Variables/1_variables_exercise.md: -------------------------------------------------------------------------------- 1 | ### Exercise: Python Variables 2 | 1. Create a variable called break and assign it a value 5. See what happens and find out the reason behind the behavior that you see. 3 | 2. Create two variables. One to store your birth year and another one to store current year. Now calculate your age using these two variables 4 | 3. Store your first, middle and last name in three different variables and then print your full name using these variables 5 | 4. Answer which of these are invalid variable names: 6 | _nation 7 | 1record 8 | record1 9 | record_one 10 | record-one 11 | record^one 12 | continue 13 | 14 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/1_Variables/Exercise/1_variables_exercise.ipynb) -------------------------------------------------------------------------------- /ML/1_linear_reg/linearReg.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Data.csv') 10 | 11 | X = dataset.iloc[:, :-1].values 12 | y = dataset.iloc[:, 3].values 13 | 14 | # Splitting the dataset into the Training set and Test set 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 17 | 18 | # Feature Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.transform(X_test) 23 | sc_y = StandardScaler() 24 | y_train = sc_y.fit_transform(y_train) 25 | -------------------------------------------------------------------------------- /Modules/argparse_tutorial.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | if __name__ == "__main__": 4 | parser = argparse.ArgumentParser() 5 | parser.add_argument("--number1", help="first number") 6 | parser.add_argument("--number2", help="second number") 7 | parser.add_argument("--operation", help="operation", \ 8 | choices=["add","subtract","multiply"]) 9 | 10 | args = parser.parse_args() 11 | 12 | print(args.number1) 13 | print(args.number2) 14 | print(args.operation) 15 | 16 | n1=int(args.number1) 17 | n2=int(args.number2) 18 | result = None 19 | if args.operation == "add": 20 | result=n1+n2 21 | elif args.operation == "subtract": 22 | result=n1-n2 23 | elif args.operation == "multiply": 24 | result=n1*n2 25 | 26 | 27 | print("Result:",result) -------------------------------------------------------------------------------- /Multiprocessing/multiprocessing_lock.py: -------------------------------------------------------------------------------- 1 | import time 2 | import multiprocessing 3 | 4 | def deposit(balance, lock): 5 | for i in range(100): 6 | time.sleep(0.01) 7 | lock.acquire() 8 | balance.value = balance.value + 1 9 | lock.release() 10 | 11 | def withdraw(balance, lock): 12 | for i in range(100): 13 | time.sleep(0.01) 14 | lock.acquire() 15 | balance.value = balance.value - 1 16 | lock.release() 17 | 18 | if __name__ == '__main__': 19 | balance = multiprocessing.Value('i', 200) 20 | lock = multiprocessing.Lock() 21 | d = multiprocessing.Process(target=deposit, args=(balance,lock)) 22 | w = multiprocessing.Process(target=withdraw, args=(balance,lock)) 23 | d.start() 24 | w.start() 25 | d.join() 26 | w.join() 27 | print(balance.value) 28 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/Exercise/poem.txt: -------------------------------------------------------------------------------- 1 | Two roads diverged in a yellow wood, 2 | And sorry I could not travel both 3 | And be one traveler, long I stood 4 | And looked down one as far as I could 5 | To where it bent in the undergrowth; 6 | 7 | Then took the other, as just as fair, 8 | And having perhaps the better claim, 9 | Because it was grassy and wanted wear; 10 | Though as for that the passing there 11 | Had worn them really about the same, 12 | 13 | And both that morning equally lay 14 | In leaves no step had trodden black. 15 | Oh, I kept the first for another day! 16 | Yet knowing how way leads on to way, 17 | I doubted if I should ever come back. 18 | 19 | I shall be telling this with a sigh 20 | Somewhere ages and ages hence: 21 | Two roads diverged in a wood, and I— 22 | I took the one less traveled by, 23 | And that has made all the difference. -------------------------------------------------------------------------------- /DataStructures/4_HashTable_2_Collisions/Solution/poem.txt: -------------------------------------------------------------------------------- 1 | Two roads diverged in a yellow wood, 2 | And sorry I could not travel both 3 | And be one traveler, long I stood 4 | And looked down one as far as I could 5 | To where it bent in the undergrowth; 6 | 7 | Then took the other, as just as fair, 8 | And having perhaps the better claim, 9 | Because it was grassy and wanted wear; 10 | Though as for that the passing there 11 | Had worn them really about the same, 12 | 13 | And both that morning equally lay 14 | In leaves no step had trodden black. 15 | Oh, I kept the first for another day! 16 | Yet knowing how way leads on to way, 17 | I doubted if I should ever come back. 18 | 19 | I shall be telling this with a sigh 20 | Somewhere ages and ages hence: 21 | Two roads diverged in a wood, and I— 22 | I took the one less traveled by, 23 | And that has made all the difference. -------------------------------------------------------------------------------- /Basics/Hindi/2_numbers/2_numbers_exercise_description.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Numbers in python 2 | 1. You have a football field that is 92 meter long and 48.8 meter wide. Find out total 3 | area using python and print it. 4 | 2. You bought 9 packets of potato chips from a store. Each packet costs 1.49 dollar 5 | and you gave shopkeeper 20 dollar. Find out using python, how many dollars is the shopkeeper going to give you back? 6 | 3. You want to replace tiles in your bathroom which is exactly square and 5.5 feet 7 | is its length. If tiles cost 500 rs per square feet, how much will be the total 8 | cost to replace all tiles. Calculate and print the cost using python 9 | (Hint: Use power operator ** to find area of a square) 10 | 4. Print binary representation of number 17 11 | 12 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/2_numbers/Exercise/2_numbers_exercise.py) -------------------------------------------------------------------------------- /DataStructures/5_Stack/Exercise/reverse_string.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | class Stack: 4 | def __init__(self): 5 | self.container = deque() 6 | 7 | def push(self, val): 8 | self.container.append(val) 9 | 10 | def pop(self): 11 | return self.container.pop() 12 | 13 | def peek(self): 14 | return self.container[-1] 15 | 16 | def is_empty(self): 17 | return len(self.container) == 0 18 | 19 | def size(self): 20 | return len(self.container) 21 | 22 | def reverse_string(s): 23 | stack = Stack() 24 | 25 | for ch in s: 26 | stack.push(ch) 27 | 28 | rstr = '' 29 | while stack.size()!=0: 30 | rstr += stack.pop() 31 | 32 | return rstr 33 | 34 | 35 | if __name__ == '__main__': 36 | print(reverse_string("We will conquere COVI-19")) 37 | print(reverse_string("I am the king")) -------------------------------------------------------------------------------- /Basics/Hindi/6_if/Exercise/6_exercise1_1.py: -------------------------------------------------------------------------------- 1 | ## Exercise: Python If Condition 2 | # 1. Using following list of cities per country, 3 | # ``` 4 | # india = ["mumbai", "banglore", "chennai", "delhi"] 5 | # pakistan = ["lahore","karachi","islamabad"] 6 | # bangladesh = ["dhaka", "khulna", "rangpur"] 7 | # ``` 8 | # Write a program that asks user to enter a city name and it should tell which country the city belongs to 9 | 10 | india = ["mumbai", "banglore", "chennai", "delhi"] 11 | pakistan = ["lahore", "karachi", "islamabad"] 12 | bangladesh = ["dhaka", "khulna", "rangpur"] 13 | 14 | city = input("Enter city name: ") 15 | 16 | if city in india: 17 | print(f"{city} is in india") 18 | elif city in pakistan: 19 | print(f"{city} is in pakistan") 20 | elif city in bangladesh: 21 | print(f"{city} is in bangladesh") 22 | else: 23 | print(f"I won't be able to tell you which country {city} is in! Sorry!") 24 | -------------------------------------------------------------------------------- /pandas/15_ts_date_range/aapl_no_dates.csv: -------------------------------------------------------------------------------- 1 | Open,High,Low,Close,Volume 2 | 153.17,153.33,152.22,153.18,16404088 3 | 153.58,155.45,152.89,155.45,27770715 4 | 154.34,154.45,153.46,153.93,25331662 5 | 153.9,155.81,153.78,154.45,26624926 6 | 155.02,155.98,154.48,155.37,21069647 7 | 155.25,155.54,154.4,154.99,21250798 8 | 155.19,155.19,146.02,148.98,64882657 9 | 145.74,146.09,142.51,145.42,72307330 10 | 147.16,147.45,145.15,146.59,34165445 11 | 147.5,147.5,143.84,145.16,31531232 12 | 143.32,144.48,142.21,144.29,32165373 13 | 143.78,144.5,142.2,142.27,50361093 14 | 143.66,146.74,143.66,146.34,32541404 15 | 146.87,146.87,144.94,145.01,24900073 16 | 145.52,146.07,144.61,145.87,21265751 17 | 145.77,146.7,145.12,145.63,19106294 18 | 145.13,147.16,145.11,146.28,35439389 19 | 147.17,148.28,145.38,145.82,25692361 20 | 145.01,146.16,143.62,143.73,24761891 21 | 144.49,146.11,143.16,145.83,22082432 22 | 144.71,145.13,142.28,143.68,31499368 23 | 144.45,144.96,143.78,144.02,23024107 24 | -------------------------------------------------------------------------------- /Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_2_stocks.py: -------------------------------------------------------------------------------- 1 | import statistics 2 | 3 | stocks = { 4 | 'info': [600,630,620], 5 | 'ril': [1430,1490,1567], 6 | 'mtl': [234,180,160] 7 | } 8 | 9 | def print_all(): 10 | for stock,price_list in stocks.items(): 11 | avg = statistics.mean(price_list) 12 | print(f"{stock} ==> {price_list} ==> avg: ",round(avg,2)) 13 | 14 | 15 | def add(): 16 | s = input("Enter a stock ticker to add:") 17 | p = input("Enter price of this stock:") 18 | p=float(p) 19 | if s in stocks: 20 | stocks[s].append(p) 21 | else: 22 | stocks[s] = [p] 23 | print_all() 24 | 25 | 26 | def main(): 27 | op=input("Enter operation (print, add or amend):") 28 | if op.lower() == 'print': 29 | print_all() 30 | elif op.lower() == 'add': 31 | add() 32 | else: 33 | print("Unsupported operation:",op) 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /DataStructures/2_Arrays/Solution/2_marvel.py: -------------------------------------------------------------------------------- 1 | # 2. You have a list of your favourite marvel super heros 2 | # heros=['spider man','thor','hulk','iron man','captain america'] 3 | # Using this list 4 | 5 | heros=['spider man','thor','hulk','iron man','captain america'] 6 | # 1. Length of the list 7 | print(len(heros)) 8 | # 2. Add 'black panther' at the end of this list 9 | heros.append('black panther') 10 | print(heros) 11 | # 3. You realize that you need to add 'black panther' after 'hulk', 12 | # so remove it from the list first and then add it after 'hulk' 13 | heros.remove('black panther') 14 | heros.insert(3,'black panther') 15 | print(heros) 16 | # 4. Now you don't like thor and hulk because they get angry easily :) 17 | # So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool). 18 | # Do that with one line of code. 19 | heros[1:3]=['doctor strange'] 20 | print(heros) 21 | # 5. Sort the list in alphabetical order 22 | heros.sort() 23 | print(heros) 24 | -------------------------------------------------------------------------------- /Basics/13_read_write_file.py: -------------------------------------------------------------------------------- 1 | def count_num_in_file(file_path, num): 2 | count = 0 3 | with open(file_path,"r") as f: 4 | for line in f.readlines(): 5 | tokens = line.split(",") 6 | count += count_num_in_tokens(tokens, num) 7 | 8 | return count 9 | 10 | def count_num_in_tokens(tokens, num): 11 | count = 0 12 | for token in tokens: 13 | if num == int(token): 14 | count+=1 15 | return count 16 | 17 | 18 | def sum_numbers(file_path): 19 | output_lines = [] 20 | with open(file_path,"r") as f: 21 | for line in f.readlines(): 22 | tokens = line.split(",") 23 | total = sum_tokens(tokens) 24 | output_lines.append("sum: " + str(total) + " | " + line) 25 | with open(file_path,"w") as f: 26 | f.writelines(output_lines) 27 | 28 | def sum_tokens(tokens): 29 | sum = 0 30 | for token in tokens: 31 | sum += int(token) 32 | return sum 33 | 34 | sum_numbers("C:\\Code\\Py\\Basics\\input.txt") -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/server/server.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify 2 | import util 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/get_location_names', methods=['GET']) 7 | def get_location_names(): 8 | response = jsonify({ 9 | 'locations': util.get_location_names() 10 | }) 11 | response.headers.add('Access-Control-Allow-Origin', '*') 12 | 13 | return response 14 | 15 | @app.route('/predict_home_price', methods=['GET', 'POST']) 16 | def predict_home_price(): 17 | total_sqft = float(request.form['total_sqft']) 18 | location = request.form['location'] 19 | bhk = int(request.form['bhk']) 20 | bath = int(request.form['bath']) 21 | 22 | response = jsonify({ 23 | 'estimated_price': util.get_estimated_price(location,total_sqft,bhk,bath) 24 | }) 25 | response.headers.add('Access-Control-Allow-Origin', '*') 26 | 27 | return response 28 | 29 | if __name__ == "__main__": 30 | print("Starting Python Flask Server For Home Price Prediction...") 31 | util.load_saved_artifacts() 32 | app.run() -------------------------------------------------------------------------------- /Basics/Hindi/8_functions/8_functions_exercise.md: -------------------------------------------------------------------------------- 1 | # Exercise: Functions in python 2 | 1. Write a function called calculate_area that takes base and height as an input and returns and area of a triangle. Equation of an area of a triangle is, 3 | ``` 4 | area = (1/2)*base*height 5 | ``` 6 | 7 | 2. Modify above function to take third parameter shape type. It can be either "triangle" or "rectangle". Based on shape type it will calculate area. Equation of rectangle's area is, 8 | ``` 9 | rectangle area=length*width 10 | ``` 11 | If no shape is supplied then it should take triangle as a default shape 12 | 13 | 3. Write a function called print_pattern that takes integer number as an argument and prints following pattern if input number is 3, 14 | ``` 15 | * 16 | ** 17 | *** 18 | ``` 19 | if input is 4 then it should print 20 | ``` 21 | * 22 | ** 23 | *** 24 | **** 25 | ``` 26 | Basically number of lines it prints is equal to that number. (Hint: you need to use two for loops) 27 | 28 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/8_functions/Exercise/8_functions_exercise.py) -------------------------------------------------------------------------------- /ML/1_linear_reg/Exercise/canada_per_capita_income.csv: -------------------------------------------------------------------------------- 1 | year,per capita income (US$) 2 | 1970,3399.299037 3 | 1971,3768.297935 4 | 1972,4251.175484 5 | 1973,4804.463248 6 | 1974,5576.514583 7 | 1975,5998.144346 8 | 1976,7062.131392 9 | 1977,7100.12617 10 | 1978,7247.967035 11 | 1979,7602.912681 12 | 1980,8355.96812 13 | 1981,9434.390652 14 | 1982,9619.438377 15 | 1983,10416.53659 16 | 1984,10790.32872 17 | 1985,11018.95585 18 | 1986,11482.89153 19 | 1987,12974.80662 20 | 1988,15080.28345 21 | 1989,16426.72548 22 | 1990,16838.6732 23 | 1991,17266.09769 24 | 1992,16412.08309 25 | 1993,15875.58673 26 | 1994,15755.82027 27 | 1995,16369.31725 28 | 1996,16699.82668 29 | 1997,17310.75775 30 | 1998,16622.67187 31 | 1999,17581.02414 32 | 2000,18987.38241 33 | 2001,18601.39724 34 | 2002,19232.17556 35 | 2003,22739.42628 36 | 2004,25719.14715 37 | 2005,29198.05569 38 | 2006,32738.2629 39 | 2007,36144.48122 40 | 2008,37446.48609 41 | 2009,32755.17682 42 | 2010,38420.52289 43 | 2011,42334.71121 44 | 2012,42665.25597 45 | 2013,42676.46837 46 | 2014,41039.8936 47 | 2015,35175.18898 48 | 2016,34229.19363 49 | -------------------------------------------------------------------------------- /pandas/contents.txt: -------------------------------------------------------------------------------- 1 | 1) Intro 2 | * what is pandas? 3 | * what using excel/plain python not good. 4 | * Show how pandas increase productivity 5 | 6 | 2) Dataframe basics 7 | * What is dataframe? 8 | * Dealing with rows and columns 9 | * Operations: mean, max, std, describe 10 | * Conditional selection 11 | * set_index 12 | 13 | 3) Different ways of creating dataframe 14 | * dictionary, tuples list, list of dictionaries, csv, excel 15 | 16 | -) reading/writing to excel/csv: http://pbpython.com/excel-pandas-comp.html 17 | 18 | -) Handling Missing Data 19 | * dropna 20 | * fillna 21 | * isnull 22 | * df.reindex 23 | 24 | -) Excel Like Operations 25 | * sort 26 | * filter 27 | * remove/rename columns 28 | * .duplicated 29 | * 30 | 31 | -) Selection of data 32 | * df['A'] or df.A 33 | * df[0:3] 34 | * df['20130102':'20130104'] 35 | * df.loc['Rain'] or df.at['Rain'] 36 | * df.iloc[3] 37 | * df.iat[1,1] 38 | * df[df.A > 0] 39 | 40 | 41 | 42 | -) Merge/Concat/Join 43 | -) Grouping 44 | -) Reshaping/Stack/Unstack 45 | -) Pivot Table 46 | -) Time Series and Categoricals 47 | -) Plotting (Bokeh?) 48 | -------------------------------------------------------------------------------- /DataStructures/5_Stack/5_stack_exercise.md: -------------------------------------------------------------------------------- 1 | ## Data structure tutorial exercise: Stack 2 | 1. Write a function in python that can reverse a string using stack data structure. Use [Stack class](https://github.com/codebasics/py/tree/master/DataStructures/5_Stack/5_stack.ipynb) from the tutorial. 3 | ``` 4 | reverse_string("We will conquere COVI-19") should return "91-IVOC ereuqnoc lliw eW" 5 | ``` 6 | 7 | [Solution](https://github.com/codebasics/py/tree/master/DataStructures/5_Stack/Exercise/reverse_string.py) 8 | 9 | 2. Write a function in python that checks if paranthesis in the string are balanced or not. Possible parantheses are "{}',"()" or "[]". Use [Stack class](https://github.com/codebasics/py/tree/master/DataStructures/5_Stack/5_stack.ipynb) from the tutorial. 10 | ``` 11 | is_balanced("({a+b})") --> True 12 | is_balanced("))((a+b}{") --> False 13 | is_balanced("((a+b))") --> True 14 | is_balanced("))") --> False 15 | is_balanced("[a+b]*(x+2y)*{gg+kk}") --> True 16 | ``` 17 | 18 | [Solution](https://github.com/codebasics/py/tree/master/DataStructures/5_Stack/Exercise/balance_paran.py) -------------------------------------------------------------------------------- /Basics/Hindi/2_numbers/2_numbers.py: -------------------------------------------------------------------------------- 1 | # 1. Use python to find area of triangle 2 | # area = (1/2)*base*height 3 | base=10.26 4 | height=20.572 5 | area=(1/2)*base*height 6 | print("area is:",area) # area is: 105.53435999999999 7 | # to show area till 2 decimal places 8 | print("area rounded to 2 decimal place:",round(area,2)) # 105.53 9 | 10 | # 2. basic airthmetic using numbers 11 | print(1+2) # 3 12 | print(1/2) # 0.5 13 | print(17%3) # 2 14 | print(3**2) # 9 15 | print(10+2*3) # 16 16 | print((10+2)*3) # 36 17 | 18 | # 3. Number data types (int, float, complex numbers) 19 | print(type(area)) # float 20 | foo=2.3e-3 21 | print(foo) # 0.0023 22 | print(type(1)) # int 23 | print(0x12) # 18 24 | print(type(0x12)) # int 25 | c1=2+3j 26 | print(type(c1)) # complex 27 | c2=3-4j 28 | print(c1+c2) # 5-j 29 | 30 | # 4. Internal representation of numbers 31 | # (a) integers are stored in simple binary format 32 | print(format(5,'b')) # 4 bytes (or 32 bits), visual of binary presentation 33 | # (b) floats use IEEE754 standard : https://en.wikipedia.org/wiki/IEEE_754 34 | print(6-5.7) # this prints 0.29999999 and not 0.3. why? Due to IEEE 754 standard 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /pandas/15_ts_date_range/aapl.csv: -------------------------------------------------------------------------------- 1 | Date,Open,High,Low,Close,Volume 2 | 1-Jun-17,153.17,153.33,152.22,153.18,16404088 3 | 2-Jun-17,153.58,155.45,152.89,155.45,27770715 4 | 5-Jun-17,154.34,154.45,153.46,153.93,25331662 5 | 6-Jun-17,153.9,155.81,153.78,154.45,26624926 6 | 7-Jun-17,155.02,155.98,154.48,155.37,21069647 7 | 8-Jun-17,155.25,155.54,154.4,154.99,21250798 8 | 9-Jun-17,155.19,155.19,146.02,148.98,64882657 9 | 12-Jun-17,145.74,146.09,142.51,145.42,72307330 10 | 13-Jun-17,147.16,147.45,145.15,146.59,34165445 11 | 14-Jun-17,147.5,147.5,143.84,145.16,31531232 12 | 15-Jun-17,143.32,144.48,142.21,144.29,32165373 13 | 16-Jun-17,143.78,144.5,142.2,142.27,50361093 14 | 19-Jun-17,143.66,146.74,143.66,146.34,32541404 15 | 20-Jun-17,146.87,146.87,144.94,145.01,24900073 16 | 21-Jun-17,145.52,146.07,144.61,145.87,21265751 17 | 22-Jun-17,145.77,146.7,145.12,145.63,19106294 18 | 23-Jun-17,145.13,147.16,145.11,146.28,35439389 19 | 26-Jun-17,147.17,148.28,145.38,145.82,25692361 20 | 27-Jun-17,145.01,146.16,143.62,143.73,24761891 21 | 28-Jun-17,144.49,146.11,143.16,145.83,22082432 22 | 29-Jun-17,144.71,145.13,142.28,143.68,31499368 23 | 30-Jun-17,144.45,144.96,143.78,144.02,23024107 24 | -------------------------------------------------------------------------------- /Basics/lists: -------------------------------------------------------------------------------- 1 | Lists 2 | ===== 3 | 4 | Let us say your expense for every month are listed below, 5 | January - 2200 6 | February - 2350 7 | March - 2600 8 | April - 2130 9 | May - 2190 10 | Create a list to store these monthly expenses and using that find out, 11 | In Feb, how many dollars you spent extra compare to January? 12 | Find out your total expense in first quarter (first three months) of the year. 13 | Find out if you spent exactly 2000 dollars in any month 14 | June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 15 | You returned an item that you bought in a month of April and got a refund of 200$. Make a correction to your monthly expense list based on this. 16 | Answer: 17 | >>> exp = [2200,2350,2600,2130,2190] 18 | 19 | # (a) 20 | >>> exp[1]-exp[0] 21 | 150 22 | 23 | # (b) 24 | >>> exp[0]+exp[1]+exp[2] 25 | 7150 26 | 27 | # (c) 28 | >>> 2000 in exp 29 | False # Means you didn’t spend 2000$ in any of the month 30 | 31 | # (d) 32 | >>> exp.append(1980) 33 | >>> exp 34 | [2200, 2350, 2600, 2130, 2190, 1980] 35 | 36 | # (e) 37 | >>> exp[3] = exp[3] - 200 38 | >>> exp[3] 39 | 1930 40 | 41 | -------------------------------------------------------------------------------- /Basics/Hindi/1_Variables/1_variables.py: -------------------------------------------------------------------------------- 1 | rent=8000 2 | petrol=500.5 3 | groceries=2050.5 4 | print(rent) 5 | total=rent+petrol+groceries 6 | 7 | gabbar="amjad khan" 8 | jay="amitabh" 9 | thakur="sanjiv kumar" 10 | 11 | print("actors in sholey: ",gabbar,jay,thakur) 12 | 13 | print(type(rent)) 14 | print(type(groceries)) 15 | print(type(gabbar)) 16 | 17 | # boolean 18 | learn_python=True 19 | learn_fortran=False 20 | 21 | # variable naming rules 22 | # no keywords: example True, for 23 | # no special characters: foo+bar 24 | # they must begin with a letter or _ 25 | # other characters can be letters (a to Z, A to Z) or numbers (0 to 9) 26 | # names are case sensitive 27 | 28 | bade_bhai=10 29 | bade_Bhai=5 30 | print(bade_bhai) 31 | print(bade_Bhai) 32 | 33 | # above naming convention is called snake_case 34 | 35 | # In python you can assign variable any value, not like strict typed language where 36 | # you have to declare data type of a variable in advance 37 | 38 | foo=5 39 | foo="jalebi" 40 | bar=foo 41 | print("bar id",id(bar)) 42 | print("foo id",id(foo)) 43 | bar="samosa" 44 | foo="kachodi" # at this point nothing is point to jalebi object and it will be garbage collected -------------------------------------------------------------------------------- /Basics/Hindi/6_if/Exercise/6_exercise1_2.py: -------------------------------------------------------------------------------- 1 | ## Exercise: Python If Condition 2 | # 1. Using following list of cities per country, 3 | # ``` 4 | # india = ["mumbai", "banglore", "chennai", "delhi"] 5 | # pakistan = ["lahore","karachi","islamabad"] 6 | # bangladesh = ["dhaka", "khulna", "rangpur"] 7 | # ``` 8 | #Write a program that asks user to enter two cities and it tells you if they both are in same country or not. For example if I enter mumbai and chennai, it will print "Both cities are in India" but if I enter mumbai and dhaka it should print "They don't belong to same country" 9 | 10 | india = ["mumbai", "banglore", "chennai", "delhi"] 11 | pakistan = ["lahore", "karachi", "islamabad"] 12 | bangladesh = ["dhaka", "khulna", "rangpur"] 13 | 14 | city1 = input("Enter city 1: ") 15 | city2 = input("Enter city 2: ") 16 | 17 | if city1 in india and city2 in india: 18 | print("Both cities are in india") 19 | elif city1 in pakistan and city2 in pakistan: 20 | print("Both cities are in pakistan") 21 | elif city1 in bangladesh and bangladesh in india: 22 | print("Both cities are in bangladesh") 23 | else: 24 | print("They don't belong to same country") -------------------------------------------------------------------------------- /Basics/Hindi/3_strings/3_strings_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: String in Python 2 | 3 | 1. Create 3 variables to store street, city and country, now create address variable to 4 | store entire address. Use two ways of creating this variable, one using + operator and the other using f-string. 5 | Now Print the address in such a way that the street, city and country prints in a separate line 6 | 2. Create a variable to store the string "Earth revolves around the sun" 7 | 1. Print "revolves" using slice operator 8 | 2. Print "sun" using negative index 9 | 3. Create two variables to store how many fruits and vegetables you eat in a day. 10 | Now Print "I eat x veggies and y fruits daily" where x and y presents vegetables and fruits that you eat everyday. Use python f string for this. 11 | 4. I have a string variable called s='maine 200 banana khaye'. This of course is a 12 | wrong statement, the correct statement is 'maine 10 samosa khaye'. 13 | Replace incorrect words in original strong with new ones and print the new string. 14 | Also try to do this in one line. 15 | 16 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/3_strings/Exercise/3_string_exercise_answer.py) 17 | -------------------------------------------------------------------------------- /Basics/Hindi/7_for/7_for.py: -------------------------------------------------------------------------------- 1 | # expense total using simple sum 2 | expenses = [1200,1500,1300,1700] 3 | total = expenses[0] + expenses[1] + expenses[2] + expenses[3] 4 | print(total) 5 | 6 | # expense total using for loop 7 | total = 0 8 | for expense in expenses: 9 | total = total + expense 10 | print(total) 11 | 12 | # explain for loop iterations by debugging code 13 | 14 | # range() function 15 | print(range(1,11)) 16 | print(list(range(1,11))) 17 | for i in range(1,11): 18 | print(i) 19 | 20 | # in monthly expense list print month number, expense and then total 21 | total = 0 22 | for i in range(len(expenses)): 23 | print(f"Month {i+1}, expense: {expenses[i]}") 24 | total += expenses[i] 25 | print(f"Total expenses is {total}") 26 | 27 | # break 28 | key_location="chair" 29 | locations = ["sofa","garage","chair","table","closet"] 30 | for loc in locations: 31 | if loc == key_location: 32 | print("Key found at:",loc) 33 | break 34 | else: 35 | print("Key not found in:",loc) 36 | 37 | # continue: print odd numbers between 1 to 10 38 | for i in range(11): 39 | if i%2==0: 40 | continue 41 | print(i) 42 | 43 | # while loop 44 | num=0 45 | while num<=10: 46 | print(num) 47 | num=num+1 -------------------------------------------------------------------------------- /Basics/Hindi/6_if/6_if.py: -------------------------------------------------------------------------------- 1 | # while mentioning topics say that timeline is in video description 2 | # so you don't need to watch entire video 3 | 4 | n=input("Enter a number") 5 | n=int(n) 6 | if n%2==0: 7 | print("Number is even") 8 | else: 9 | print("Number is odd") 10 | 11 | 12 | # Show the execution by debugging 13 | # If is called control statement as it controls the flow of code execution 14 | 15 | # go to idle and explain different operators 16 | 17 | # == 18 | # != 19 | # > 20 | # < 21 | # >= 22 | # <= 23 | # 24 | # 3>2 and 4>1 25 | # 3>1 or 4>8 26 | # not 4==4 27 | 28 | 29 | # Cousine checker. Explains if..elif..else 30 | indian=["samosa","kachori","dal","naan"] 31 | pakistani=["nihari","paya","karahi"] 32 | bangladesi=["panta bhat","chorchori","fuchka"] 33 | 34 | dish=input("Enter a dish name:") 35 | 36 | if dish in indian: 37 | print(f"{dish} is Indian") 38 | elif dish in pakistani: 39 | print(f"{dish} is pakistani") 40 | elif dish in bangladesi: 41 | print(f"{dish} is bangladesi") 42 | else: 43 | print(f"Based on my limited knowledge, I don't know which cuisine is {dish}") 44 | 45 | 46 | # Ternary operator 47 | print("Ternary operator demo") 48 | n=input("Enter a number:") 49 | n=int(n) 50 | message="Number is even" if n%2==0 else "Number is odd" 51 | print(message) 52 | -------------------------------------------------------------------------------- /Basics/Hindi/7_for/7_for_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python for loop 2 | 1. After flipping a coin 10 times you got this result, 3 | ``` 4 | result = ["heads","tails","tails","heads","tails","heads","heads","tails","tails","tails"] 5 | ``` 6 | Using for loop figure out how many times you got heads 7 | 8 | 2. Print square of all numbers between 1 to 10 except even numbers 9 | 3. Your monthly expense list (from Jan to May) looks like this, 10 | ``` 11 | expense_list = [2340, 2500, 2100, 3100, 2980] 12 | ``` 13 | Write a program that asks you to enter an expense amount and program 14 | should tell you in which month that expense occurred. If expense is not 15 | found then it should print that as well. 16 | 17 | 4. Lets say you are running a 5 km race. Write a program that, 18 | 1. Upon completing each 1 km asks you "are you tired?" 19 | 2. If you reply "yes" then it should break and print "you didn't finish the race" 20 | 3. If you reply "no" then it should continue and ask "are you tired" on every km 21 | 4. If you finish all 5 km then it should print congratulations message 22 | 23 | 5. Write a program that prints following shape 24 | ``` 25 | * 26 | ** 27 | *** 28 | **** 29 | ***** 30 | ``` 31 | 32 | 33 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/7_for/Exercise/7_for_exercise.py) -------------------------------------------------------------------------------- /Basics/Hindi/2_numbers/Exercise/2_numbers_exercise.py: -------------------------------------------------------------------------------- 1 | # Exercise 2 | # 1. You have a football field that is 92 meter long and 48.8 meter wide. Find out total 3 | # area using python and print it 4 | length=92 5 | width=48.8 6 | area=length*width 7 | print("area of football field:",area) # Ans: 4489.599999999999 8 | 9 | # 2. You bought 9 packets of potato chips from a store. Each packet costs 1.49 dollar 10 | # and you gave shopkeeper 20 dollar. 11 | # Find out using python, how many dollars is the shopkeeper going to give you back? 12 | num_packets=9 13 | cost_per_packet=1.49 14 | total_cost=num_packets*cost_per_packet 15 | money_paid=20 16 | cash_back=money_paid-total_cost 17 | print("Cash back:",cash_back) # Ans: 6.59 18 | 19 | # 3. You want to replace tiles in your bathroom which is exactly square and 5.5 feet 20 | # is its length. If tiles cost 500 rs per square feet, how much will be the total 21 | # cost to replace all tiles. Calculate and print the cost using python 22 | # Hint: Use power operator (**) to find area of a square 23 | length=5.5 24 | area=length**2 # area of square is length power 2 25 | cost=area*500 26 | print("total cost for bathroom tiles replacement:",cost) # Ans: 15125.0 27 | 28 | # 4. Print binary representation of number 17 29 | num=17 30 | print('Binary of number 17 is:',format(num,'b')) # Ans: 10001 -------------------------------------------------------------------------------- /DataStructures/5_Stack/Exercise/balance_paran.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | class Stack: 4 | def __init__(self): 5 | self.container = deque() 6 | 7 | def push(self, val): 8 | self.container.append(val) 9 | 10 | def pop(self): 11 | return self.container.pop() 12 | 13 | def peek(self): 14 | return self.container[-1] 15 | 16 | def is_empty(self): 17 | return len(self.container) == 0 18 | 19 | def size(self): 20 | return len(self.container) 21 | 22 | def is_match(ch1, ch2): 23 | match_dict = { 24 | ')': '(', 25 | ']': '[', 26 | '}': '{' 27 | } 28 | return match_dict[ch1] == ch2 29 | 30 | 31 | def is_balanced(s): 32 | stack = Stack() 33 | for ch in s: 34 | if ch=='(' or ch=='{' or ch == '[': 35 | stack.push(ch) 36 | if ch==')' or ch=='}' or ch == ']': 37 | if stack.size()==0: 38 | return False 39 | if not is_match(ch,stack.pop()): 40 | return False 41 | 42 | return stack.size()==0 43 | 44 | 45 | if __name__ == '__main__': 46 | print(is_balanced("({a+b})")) 47 | print(is_balanced("))((a+b}{")) 48 | print(is_balanced("((a+b))")) 49 | print(is_balanced("((a+g))")) 50 | print(is_balanced("))")) 51 | print(is_balanced("[a+b]*(x+2y)*{gg+kk}")) 52 | -------------------------------------------------------------------------------- /Basics/Hindi/6_if/6_exercise_description.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python If Condition 2 | 1. Using following list of cities per country, 3 | ``` 4 | india = ["mumbai", "banglore", "chennai", "delhi"] 5 | pakistan = ["lahore","karachi","islamabad"] 6 | bangladesh = ["dhaka", "khulna", "rangpur"] 7 | ``` 8 | 1. Write a program that asks user to enter a city name and it should tell which country the city belongs to 9 | 2. Write a program that asks user to enter two cities and it tells you if they both are in same country or not. For example if I enter mumbai and chennai, it will print "Both cities are in India" but if I enter mumbai and dhaka it should print "They don't belong to same country" 10 | 2. Write a python program that can tell you if your sugar is normal or not. Normal fasting level sugar range is 80 to 100. 11 | 1. Ask user to enter his fasting sugar level 12 | 2. If it is below 80 to 100 range then print that sugar is low 13 | 3. If it is above 100 then print that it is high otherwise print that it is normal 14 | 15 | [Solution - Exercise 1.i](https://github.com/codebasics/py/blob/master/Basics/Hindi/6_if/Exercise/6_exercise1_1.py) 16 | 17 | [Solution - Exercise 1.ii](https://github.com/codebasics/py/blob/master/Basics/Hindi/6_if/Exercise/6_exercise1_2.py) 18 | 19 | [Solution - Exercise 2](https://github.com/codebasics/py/blob/master/Basics/Hindi/6_if/Exercise/6_exercise2.py) -------------------------------------------------------------------------------- /Basics/Hindi/8_functions/8_functions.py: -------------------------------------------------------------------------------- 1 | # Calculate expense sum for two lists without function 2 | bharat_expenses = [20,30,45] 3 | bilal_expenses = [45,67,34] 4 | 5 | total=0 6 | for item in bharat_expenses: 7 | total+=item 8 | print("Bharat's total:",total) 9 | 10 | total=0 11 | for item in bilal_expenses: 12 | total+=item 13 | print("Bilal's total:",total) 14 | 15 | # Calculate expense sum for two lists by using a function 16 | def find_total(exp): 17 | ''' 18 | This function takes list of numbers as input and returns sum of that list 19 | :param exp: input list 20 | :return: total sum 21 | ''' 22 | total=0 23 | for item in exp: 24 | total+=item 25 | return total 26 | 27 | bharat_total=find_total(bharat_expenses) 28 | print("Bharat's total:",bharat_total) 29 | 30 | bilal_total=find_total(bilal_expenses) 31 | print("Bilal's total:",bilal_total) 32 | 33 | # Explain argument, return value, function body with visuals 34 | 35 | # documentation strings 36 | print(help(find_total)) 37 | 38 | # Positional argument vs named arguments 39 | def cylinder_volume(radius,height=1): 40 | print("radius is:",radius) 41 | print("height is:",height) 42 | area = 3.14*(radius**2)*height 43 | return area 44 | 45 | r=5 46 | h=10 47 | print(cylinder_volume(height=h,radius=r)) 48 | 49 | # default arguments 50 | r=5 51 | h=10 52 | print(cylinder_volume(radius=r)) 53 | 54 | # global vs local variables 55 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/read_write_file_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python Read Write File 2 | 1. [poem.txt](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/poem.txt) contains famous poem "Road not taken" by poet Robert Frost. You have to read this file in your python program and find out words with maximum occurance. 3 | 4 | 5 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/exercise_1_poem.py) 6 | 7 | 2. [stocks.csv](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/stocks.csv) contains stock price, earnings per share and book value. You are writing a stock market application that will process this file and create a new file 8 | with financial metrics such as pe ratio and price to book ratio. These are calculated as, 9 | ``` 10 | pe ratio = price / earnings per share 11 | price to book ratio = price / book value 12 | ``` 13 | 14 | 15 | Your input format (stocks.csv) is, 16 | 17 | |Company Name|Price|Earnings Per Share|Book Value| 18 | |-------|----------|-------|----------| 19 | |Reliance|1467|66|653| 20 | |Tata Steel|391|89|572| 21 | 22 | Output.csv should look like this, 23 | 24 | |Company Name|PE Ratio|PB Ratio| 25 | |-------|----------|-------| 26 | |Reliance|22.23|2.25| 27 | |Tata Steel|4.39|0.68| 28 | 29 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/Exercise/exercise_2_stocks.py) 30 | -------------------------------------------------------------------------------- /Basics/dict_tuple.py: -------------------------------------------------------------------------------- 1 | def add_and_multiple(n1,n2): 2 | ''' 3 | Exercise 2 4 | :param n1: Number 1 5 | :param n2: Number 2 6 | :return: a tuple containing sum and multiplication of two input numbers 7 | ''' 8 | sum = n1 + n2 9 | mult = n1 * n2 10 | return sum, mult 11 | 12 | def age_dictionary(): 13 | ''' 14 | Exercise 1 15 | This program asks for person name and age and builds a dictionary using that 16 | Later on you can input person name and it will tell you the age of that person 17 | :return: 18 | ''' 19 | d = {} 20 | while True: 21 | person = input("Enter name of the person(To stop don't enter anything and hi Enter key):") 22 | if person == '': 23 | break 24 | age = input("Enter age:") 25 | d[person] = age 26 | 27 | print("Building dictionary is complete.Now enter name of the person and I'll tell you his/her age") 28 | while True: 29 | name = input("Enter name of the person(To stop don't enter anything and hi Enter key):") 30 | if name == '': 31 | break 32 | if name in d: 33 | print ("Age of", name, "is:", d[name]) 34 | else: 35 | print ("I don't know the age of",name) 36 | print ("Age dictionary program is finished now") 37 | 38 | # Exercise 1 39 | age_dictionary() 40 | 41 | # Exercise 2 42 | n1=4 43 | n2=6 44 | s,m=add_and_multiple(n1,n2) 45 | print("sum:",s,"multipication:",m," Input numbers:",n1,"and",n2) 46 | -------------------------------------------------------------------------------- /pandas/1_intro/nyc_weather.csv: -------------------------------------------------------------------------------- 1 | EST,Temperature,DewPoint,Humidity,Sea Level PressureIn,VisibilityMiles,WindSpeedMPH,PrecipitationIn,CloudCover,Events,WindDirDegrees 2 | 1/1/2016,38,23,52,30.03,10,8,0,5,,281 3 | 1/2/2016,36,18,46,30.02,10,7,0,3,,275 4 | 1/3/2016,40,21,47,29.86,10,8,0,1,,277 5 | 1/4/2016,25,9,44,30.05,10,9,0,3,,345 6 | 1/5/2016,20,-3,41,30.57,10,5,0,0,,333 7 | 1/6/2016,33,4,35,30.5,10,4,0,0,,259 8 | 1/7/2016,39,11,33,30.28,10,2,0,3,,293 9 | 1/8/2016,39,29,64,30.2,10,4,0,8,,79 10 | 1/9/2016,44,38,77,30.16,9,8,T,8,Rain,76 11 | 1/10/2016,50,46,71,29.59,4,,1.8,7,Rain,109 12 | 1/11/2016,33,8,37,29.92,10,,0,1,,289 13 | 1/12/2016,35,15,53,29.85,10,6,T,4,,235 14 | 1/13/2016,26,4,42,29.94,10,10,0,0,,284 15 | 1/14/2016,30,12,47,29.95,10,5,T,7,,266 16 | 1/15/2016,43,31,62,29.82,9,5,T,2,,101 17 | 1/16/2016,47,37,70,29.52,8,7,0.24,7,Rain,340 18 | 1/17/2016,36,23,66,29.78,8,6,0.05,6,Fog-Snow,345 19 | 1/18/2016,25,6,53,29.83,9,12,T,2,Snow,293 20 | 1/19/2016,22,3,42,30.03,10,11,0,1,,293 21 | 1/20/2016,32,15,49,30.13,10,6,0,2,,302 22 | 1/21/2016,31,11,45,30.15,10,6,0,1,,312 23 | 1/22/2016,26,6,41,30.21,9,,0.01,3,Snow,34 24 | 1/23/2016,26,21,78,29.77,1,16,2.31,8,Fog-Snow,42 25 | 1/24/2016,28,11,53,29.92,8,6,T,3,Snow,327 26 | 1/25/2016,34,18,54,30.25,10,3,0,2,,286 27 | 1/26/2016,43,29,56,30.03,10,7,0,2,,244 28 | 1/27/2016,41,22,45,30.03,10,7,T,3,Rain,311 29 | 1/28/2016,37,20,51,29.9,10,5,0,1,,234 30 | 1/29/2016,36,21,50,29.58,10,8,0,4,,298 31 | 1/30/2016,34,16,46,30.01,10,7,0,0,,257 32 | 1/31/2016,46,28,52,29.9,10,5,0,0,,241 33 | -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/read_write_with_flask/flask_with_excel.py: -------------------------------------------------------------------------------- 1 | from flask import * 2 | import pandas as pd 3 | import os 4 | import re 5 | app = Flask(__name__) 6 | 7 | @app.route("/") 8 | def show_tables(): 9 | filename = 'example2.xlsx' 10 | data = pd.read_excel(filename,sheetname='Sheet1') 11 | data = data.fillna('') 12 | return render_template('index.html',tables=[re.sub(' mytable', '" id="example', data.to_html(classes='mytable'))], 13 | titles = ['Excel Data to Flask']) 14 | 15 | 16 | 17 | @app.route('/insert', methods= ['POST','GET']) 18 | def insert(): 19 | q1 = request.form['num1'] 20 | q2 = request.form['num2'] 21 | print(q1,q2) 22 | df = pd.DataFrame({'a': [q1], 23 | 'b': [q2]}) 24 | 25 | book = pd.read_excel('example2.xlsx') 26 | writer = pd.ExcelWriter('example2.xlsx', engine='openpyxl') 27 | book.to_excel(writer, startrow=0, index=False) 28 | df.to_excel(writer, startrow=len(book) + 1, header=False, index=False) 29 | writer.save() 30 | return redirect('/') 31 | 32 | @app.route('/save', methods= ['POST','GET']) 33 | def save(): 34 | url = 'http://127.0.0.1:5000/' 35 | urll = request.get_data() 36 | print(urll) 37 | data = pd.read_html(urll) 38 | print(data) 39 | writer = pd.ExcelWriter('example2.xlsx', engine='openpyxl') 40 | data[0].drop('Unnamed: 0', axis=1).to_excel(writer, sheet_name='Sheet1', index=False) 41 | 42 | writer.save() 43 | return redirect('/') 44 | 45 | if __name__ == "__main__": 46 | app.run(debug=True) 47 | -------------------------------------------------------------------------------- /Basics/Hindi/12_read_write_file/12_read_write_file.py: -------------------------------------------------------------------------------- 1 | # read file 2 | f=open("funny.txt","r") 3 | for line in f: 4 | print(line) 5 | f.close() 6 | 7 | # readlines() 8 | f=open("funny.txt","r") 9 | lines = f.readlines() 10 | print(lines) 11 | 12 | # write file 13 | f=open("love.txt","w") 14 | f.write("I love python") 15 | f.close() 16 | 17 | # same file when you write i love javascript the previous line goes away 18 | f=open("love.txt","w") 19 | f.write("I love javascript") 20 | f.close() 21 | 22 | # You can use append mode to stop having previous lines overwritten 23 | f=open("love.txt","a") 24 | f.write("I love javascript") 25 | f.close() 26 | 27 | # show a picture of file open modes (12:12 in old video) 28 | 29 | # writelines 30 | f=open("love.txt","w") 31 | f.writelines(["I love C++\n","I love scala"]) 32 | f.close() 33 | 34 | # with statement 35 | with open("funny.txt","r") as f: 36 | for line in f: 37 | print(line) 38 | 39 | # https://www.cricketworldcup.com/teams/india/players/107 40 | player_scores = {} 41 | with open("scores.csv","r") as f: 42 | for line in f: 43 | tokens = line.split(',') 44 | player = tokens[0] 45 | score = int(tokens[1]) 46 | if player in player_scores: 47 | player_scores[player].append(score) 48 | else: 49 | player_scores[player] = [score] 50 | 51 | print(player_scores) 52 | 53 | for player, score_list in player_scores.items(): 54 | min_score=min(score_list) 55 | max_score=max(score_list) 56 | avg_score=sum(score_list)/len(score_list) 57 | 58 | print(f"{player}==>Min:{min_score}, Max:{max_score}, Avg:{avg_score}") 59 | -------------------------------------------------------------------------------- /Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_1_country_population.py: -------------------------------------------------------------------------------- 1 | population = { 2 | 'china': 143, 3 | 'india': 136, 4 | 'usa': 32, 5 | 'pakistan': 21 6 | } 7 | 8 | def add(): 9 | country=input("Enter country name to add:") 10 | country=country.lower() 11 | if country in population: 12 | print("Country already exist in our dataset. Terminating") 13 | return 14 | p=input(f"Enter population for {country}") 15 | p=float(p) 16 | population[country]=p # Adds new key value pair to dictionary 17 | print_all() 18 | 19 | def remove(): 20 | country = input("Enter country name to remove:") 21 | country = country.lower() 22 | if country not in population: 23 | print("Country doesn't exist in our dataset. Terminating") 24 | return 25 | del population[country] 26 | print_all() 27 | 28 | def query(): 29 | country = input("Enter country name to query:") 30 | country = country.lower() 31 | if country not in population: 32 | print("Country doesn't exist in our dataset. Terminating") 33 | return 34 | print(f"Population of {country} is: {population[country]} crore") 35 | 36 | def print_all(): 37 | for country, p in population.items(): 38 | print(f"{country}==>{p}") 39 | 40 | def main(): 41 | op=input("Enter operation (add, remove, query or print):") 42 | if op.lower() == 'add': 43 | add() 44 | elif op.lower() == 'remove': 45 | remove() 46 | elif op.lower() == 'query': 47 | query() 48 | elif op.lower() == 'print': 49 | print_all() 50 | 51 | if __name__ == '__main__': 52 | main() -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/server/util.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import json 3 | import numpy as np 4 | 5 | __locations = None 6 | __data_columns = None 7 | __model = None 8 | 9 | def get_estimated_price(location,sqft,bhk,bath): 10 | try: 11 | loc_index = __data_columns.index(location.lower()) 12 | except: 13 | loc_index = -1 14 | 15 | x = np.zeros(len(__data_columns)) 16 | x[0] = sqft 17 | x[1] = bath 18 | x[2] = bhk 19 | if loc_index>=0: 20 | x[loc_index] = 1 21 | 22 | return round(__model.predict([x])[0],2) 23 | 24 | 25 | def load_saved_artifacts(): 26 | print("loading saved artifacts...start") 27 | global __data_columns 28 | global __locations 29 | 30 | with open("./artifacts/columns.json", "r") as f: 31 | __data_columns = json.load(f)['data_columns'] 32 | __locations = __data_columns[3:] # first 3 columns are sqft, bath, bhk 33 | 34 | global __model 35 | if __model is None: 36 | with open('./artifacts/banglore_home_prices_model.pickle', 'rb') as f: 37 | __model = pickle.load(f) 38 | print("loading saved artifacts...done") 39 | 40 | def get_location_names(): 41 | return __locations 42 | 43 | def get_data_columns(): 44 | return __data_columns 45 | 46 | if __name__ == '__main__': 47 | load_saved_artifacts() 48 | print(get_location_names()) 49 | print(get_estimated_price('1st Phase JP Nagar',1000, 3, 3)) 50 | print(get_estimated_price('1st Phase JP Nagar', 1000, 2, 2)) 51 | print(get_estimated_price('Kalhalli', 1000, 2, 2)) # other location 52 | print(get_estimated_price('Ejipura', 1000, 2, 2)) # other location -------------------------------------------------------------------------------- /Basics/Hindi/5_lists/5_lists_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python Lists 2 | 1. Let us say your expense for every month are listed below, 3 | 1. January - 2200 4 | 2. February - 2350 5 | 3. March - 2600 6 | 4. April - 2130 7 | 5. May - 2190 8 | 9 | Create a list to store these monthly expenses and using that find out, 10 | 11 | 1. In Feb, how many dollars you spent extra compare to January? 12 | 2. Find out your total expense in first quarter (first three months) of the year. 13 | 3. Find out if you spent exactly 2000 dollars in any month 14 | 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 15 | 5. You returned an item that you bought in a month of April and 16 | got a refund of 200$. Make a correction to your monthly expense list 17 | based on this 18 | 19 | 2. You have a list of your favourite marvel super heros. 20 | ``` 21 | heros=['spider man','thor','hulk','iron man','captain america'] 22 | ``` 23 | 24 | Using this find out, 25 | 26 | 1. Length of the list 27 | 2. Add 'black panther' at the end of this list 28 | 3. You realize that you need to add 'black panther' after 'hulk', 29 | so remove it from the list first and then add it after 'hulk' 30 | 4. Now you don't like thor and hulk because they get angry easily :) 31 | So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool). 32 | Do that with one line of code. 33 | 5. Sort the heros list in alphabetical order (Hint. Use dir() functions to list down all functions available in list) 34 | 35 | 36 | 37 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/5_lists/Exercise/5_lists_exercise.py) 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Basics/Hindi/3_strings/Exercise/3_string_exercise_answer.py: -------------------------------------------------------------------------------- 1 | # 1. Create 3 variables to store street, city and country, now create address variable to 2 | # store entire address. Use two ways of creating this variable, one using + operator and the other using f-string. 3 | # Now Print the address in such a way that the street, city and country prints in a separate line 4 | street = "13 patli gali" 5 | city = "New Delhi" 6 | country = "India" 7 | address = street + '\n' + city + '\n' + country 8 | print("Address using + operator:",address) 9 | address = f'{street}\n{city}\n{country}' 10 | print("Address using f-string:",address) 11 | 12 | # 2. Create a variable to store the string "Earth revolves around the sun" 13 | # 1. Print "revolves" using slice operator 14 | # 2. Print "sun" using negative index 15 | s='Earth revolves around the sun' 16 | print(s[6:14]) 17 | print(s[-3:]) 18 | 19 | # 3. Create two variables to store how many fruits and vegetables you eat in a day. 20 | # Now Print "I eat x veggies and y fruits daily" where x and y presents vegetables and fruits that you eat everyday. 21 | # Use python f string for this. 22 | num_fruits=10 23 | num_veggies=5 24 | print(f"I eat {num_veggies} veggies and {num_fruits} daily") 25 | 26 | # 4. I have a string variable called s='maine 200 banana khaye'. This of course is a 27 | # wrong statement, the correct statement is 'maine 10 samosa khaye'. 28 | # Replace incorrect words in original strong with new ones and print the new string. 29 | # Also try to do this in one line. 30 | s='maine 200 banana khaye' 31 | s=s.replace('banana','samosa') 32 | s=s.replace('200','10') 33 | print("Using two line replace:",s) 34 | 35 | s='maine 200 banana khaye' 36 | s=s.replace('banana','samosa').replace('200','10') 37 | print("Using single line:",s) -------------------------------------------------------------------------------- /DataStructures/2_Arrays/Solution/1_expenses.py: -------------------------------------------------------------------------------- 1 | # 1. Let us say your expense for every month are listed below, 2 | # 1. January - 2200 3 | # 2. February - 2350 4 | # 3. March - 2600 5 | # 4. April - 2130 6 | # 5. May - 2190 7 | # 8 | # Create a list to store these monthly expenses and using that find out, 9 | # 10 | # 1. In Feb, how many dollars you spent extra compare to January? 11 | # 2. Find out your total expense in first quarter (first three months) of the year. 12 | # 3. Find out if you spent exactly 2000 dollars in any month 13 | # 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 14 | # 5. You returned an item that you bought in a month of April and 15 | # got a refund of 200$. Make a correction to your monthly expense list 16 | # based on this 17 | 18 | exp = [2200,2350,2600,2130,2190] 19 | 20 | # 1. In Feb, how many dollars you spent extra compare to January? 21 | print("In feb this much extra was spent compared to jan:",exp[1]-exp[0]) # 150 22 | 23 | # 2. Find out your total expense in first quarter (first three months) of the year 24 | print("Expense for first quarter:",exp[0]+exp[1]+exp[2]) # 7150 25 | 26 | # 3. Find out if you spent exactly 2000 dollars in any month 27 | print("Did I spent 2000$ in any month? ", 2000 in exp) # False 28 | 29 | # 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 30 | exp.append(1980) 31 | print("Expenses at the end of June:",exp) # [2200, 2350, 2600, 2130, 2190, 1980] 32 | 33 | # 5. You returned an item that you bought in a month of April and 34 | # got a refund of 200$. Make a correction to your monthly expense list 35 | # based on this 36 | exp[3] = exp[3] - 200 37 | print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190, 1980] 38 | -------------------------------------------------------------------------------- /Basics/if.py: -------------------------------------------------------------------------------- 1 | def city_checker(): 2 | '''if chapter exercise (a)''' 3 | 4 | usa = ["atlanta", "new york", "chicago", "baltimore"] 5 | uk = ["london", "bristol", "cambridge"] 6 | india = ["mumbai", "delhi", "banglore"] 7 | 8 | city = input("Enter city name: ") 9 | 10 | if city in usa: 11 | print(city,"is in usa") 12 | elif city in uk: 13 | print(city,"is in uk") 14 | elif city in india: 15 | print(city,"is in india") 16 | else: 17 | print("I won't be able to tell you which country",city,"is in! Sorry!") 18 | 19 | 20 | def city_country_checker(): 21 | '''if chapter exercise (b)''' 22 | 23 | usa = ["atlanta", "new york", "chicago", "baltimore"] 24 | uk = ["london", "bristol", "cambridge"] 25 | india = ["mumbai", "delhi", "banglore"] 26 | 27 | city1 = input("Enter city 1: ") 28 | city2 = input("Enter city 2: ") 29 | 30 | if city1 in usa and city2 in usa: 31 | print("Both cities are in USA") 32 | elif city1 in uk and city2 in uk: 33 | print("Both cities are in uk") 34 | elif city1 in india and city2 in india: 35 | print("Both cities are in India") 36 | else: 37 | print("They don't belong to same country") 38 | 39 | 40 | def cuisine_checker(): 41 | '''If tutorial''' 42 | 43 | indian = ["samosa","kachori", "dal", "naan" ] 44 | chinese = ["egg roll", "fried rice", "pot sticker"] 45 | italian = ["pizza", "pasta", "risotto"] 46 | 47 | dish = input("Enter a dish name: ") 48 | if dish in indian: 49 | print(dish,"is an indian cuisine") 50 | elif dish in chinese: 51 | print(dish,"is a chinese cuisine") 52 | elif dish in italian: 53 | print(dish,"is an italian cuisine") 54 | else: 55 | print("Based on whatever little knowledge I've, I can't tell which cuisine is",dish) 56 | 57 | 58 | city_checker() -------------------------------------------------------------------------------- /ML/3_gradient_descent/Exercise/ex_gradient_descent.py: -------------------------------------------------------------------------------- 1 | ''' Good students always try to solve exercise on their own first and then look at the ready made solution 2 | I know you are an awesome student !! :) 3 | Hence you will look into this code only after you have done your due diligence. 4 | If you are not an awesome student who is full of laziness then only you will come here 5 | without writing single line of code on your own. In that case anyways you are going to 6 | face my anger with fire and fury !!! 7 | ''' 8 | 9 | import numpy as np 10 | import pandas as pd 11 | from sklearn.linear_model import LinearRegression 12 | import math 13 | 14 | def predict_using_sklean(): 15 | df = pd.read_csv("test_scores.csv") 16 | r = LinearRegression() 17 | r.fit(df[['math']],df.cs) 18 | return r.coef_, r.intercept_ 19 | 20 | def gradient_descent(x,y): 21 | m_curr = 0 22 | b_curr = 0 23 | iterations = 1000000 24 | n = len(x) 25 | learning_rate = 0.0002 26 | 27 | cost_previous = 0 28 | 29 | for i in range(iterations): 30 | y_predicted = m_curr * x + b_curr 31 | cost = (1/n)*sum([value**2 for value in (y-y_predicted)]) 32 | md = -(2/n)*sum(x*(y-y_predicted)) 33 | bd = -(2/n)*sum(y-y_predicted) 34 | m_curr = m_curr - learning_rate * md 35 | b_curr = b_curr - learning_rate * bd 36 | if math.isclose(cost, cost_previous, rel_tol=1e-20): 37 | break 38 | cost_previous = cost 39 | print ("m {}, b {}, cost {}, iteration {}".format(m_curr,b_curr,cost, i)) 40 | 41 | return m_curr, b_curr 42 | 43 | if __name__ == "__main__": 44 | df = pd.read_csv("test_scores.csv") 45 | x = np.array(df.math) 46 | y = np.array(df.cs) 47 | 48 | m, b = gradient_descent(x,y) 49 | print("Using gradient descent function: Coef {} Intercept {}".format(m, b)) 50 | 51 | m_sklearn, b_sklearn = predict_using_sklean() 52 | print("Using sklearn: Coef {} Intercept {}".format(m_sklearn,b_sklearn)) 53 | 54 | -------------------------------------------------------------------------------- /DataStructures/2_Arrays/2_arrays_exercise.md: -------------------------------------------------------------------------------- 1 | # Exercise: Array DataStructure 2 | 3 | 1. Let us say your expense for every month are listed below, 4 | 1. January - 2200 5 | 2. February - 2350 6 | 3. March - 2600 7 | 4. April - 2130 8 | 5. May - 2190 9 | 10 | Create a list to store these monthly expenses and using that find out, 11 | 12 | 1. In Feb, how many dollars you spent extra compare to January? 13 | 2. Find out your total expense in first quarter (first three months) of the year. 14 | 3. Find out if you spent exactly 2000 dollars in any month 15 | 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 16 | 5. You returned an item that you bought in a month of April and 17 | got a refund of 200$. Make a correction to your monthly expense list 18 | based on this 19 | 20 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/2_Arrays/Solution/1_expenses.py) 21 | 22 | 2. You have a list of your favourite marvel super heros. 23 | ``` 24 | heros=['spider man','thor','hulk','iron man','captain america'] 25 | ``` 26 | 27 | Using this find out, 28 | 29 | 1. Length of the list 30 | 2. Add 'black panther' at the end of this list 31 | 3. You realize that you need to add 'black panther' after 'hulk', 32 | so remove it from the list first and then add it after 'hulk' 33 | 4. Now you don't like thor and hulk because they get angry easily :) 34 | So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool). 35 | Do that with one line of code. 36 | 5. Sort the heros list in alphabetical order (Hint. Use dir() functions to list down all functions available in list) 37 | 38 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/2_Arrays/Solution/2_marvel.py) 39 | 40 | 41 | 3. Create a list of all odd numbers between 1 and a max number. 42 | Max number is something you need to take from a user using input() function 43 | 44 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/2_Arrays/Solution/3_odd_even_numbers.py) 45 | 46 | -------------------------------------------------------------------------------- /DataStructures/4_HashTable_2_Collisions/4_hash_table_exercise.md: -------------------------------------------------------------------------------- 1 | # Exercise: Hash Table 2 | 3 | 1. [nyc_weather.csv](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/nyc_weather.csv) contains new york city weather for first few days in the month of January. Write a program that can answer following, 4 | 1. What was the average temperature in first week of Jan 5 | 1. What was the maximum temperature in first 10 days of Jan 6 | 7 | Figure out data structure that is best for this problem 8 | 9 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/weather_analysis.ipynb) 10 | 11 | 2. [nyc_weather.csv](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/nyc_weather.csv) contains new york city weather for first few days in the month of January. Write a program that can answer following, 12 | 1. What was the temperature on Jan 9? 13 | 1. What was the temperature on Jan 4? 14 | 15 | Figure out data structure that is best for this problem 16 | 17 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/weather_analysis.ipynb) 18 | 19 | 3. [poem.txt](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/poem.txt) Contains famous poem "Road not taken" by poet Robert Frost. You have to read this file in python and print every word and its count as show below. Think about the best data structure that you can use to solve this problem and figure out why you selected that specific data structure. 20 | ``` 21 | 'diverged': 2, 22 | 'in': 3, 23 | 'I': 8 24 | ``` 25 | 26 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/exercise_poem_find_word_occurances.ipynb) 27 | 28 | 4. Implement hash table where collisions are handled using linear probing. We learnt about linear probing in the video tutorial. Take the hash table implementation that uses chaining and modify methods to use **linear probing**. Keep MAX size of arr in hashtable as 10. 29 | 30 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/4_HashTable_2_Collisions/Solution/exercise_hash_table_linear_probing.ipynb) 31 | 32 | -------------------------------------------------------------------------------- /Basics/variable_numbers_strings.py: -------------------------------------------------------------------------------- 1 | variables 2 | ========= 3 | >>> first="Tom" 4 | >>> middle="Cruise" 5 | >>> last="Mapother" 6 | >>> print("Full Name:",first,middle,last) 7 | Full Name: Tom Cruise Mapother 8 | 9 | numbers 10 | ======= 11 | (1) Find out an area of a triangle whose base is 15 meter and height is 22 meter. The mathematical equation for an area of a triangle is: Area = ½*Base*Height 12 | >>> base=15 13 | >>> height=22 14 | >>> area=1/2*(base*height) 15 | >>> area 16 | 165.0 17 | 18 | (2) You bought 9 packets of potato chips from a store. Each packet costs 1.49 dollar and you gave shopkeeper 20 dollar. Find out using python, how many dollars is the shopkeeper going to give you back? 19 | >>> num_packets=9 20 | >>> cost_per_packet=1.49 21 | >>> total_cost=num_packets*cost_per_packet 22 | >>> money_paid=20 23 | >>> cash_back=money_paid-total_cost 24 | >>> cash_back 25 | 6.59 26 | 27 | (3) The bathroom of your home is an exact square. You want to replace tiles in it. Length of this bathroom is 5.5 feet. How many square foot of tiles you need to buy? Equation for an area of a square is: Area = Length to the power of 2. Find it out using python. 28 | >>> length=5.5 29 | >>> area=length**2 30 | >>> area 31 | 30.25 32 | 33 | strings 34 | ======= 35 | (1) Create a string variable to store this text "Earth revolves around the sun", 36 | (a) Print substring “revolves” 37 | (b) Print substring “sun” using negative index 38 | >>> s="Earth revolves around the sun" 39 | >>> s[6:14] 40 | 'revolves' 41 | >>> s[-3:] 42 | 'sun' 43 | (2) Create a string variable to store this text "Earth revolves around the “sun”" and print it 44 | >>> s='Earth revolves around the “sun”' 45 | >>> s 46 | 'Earth revolves around the “sun”' 47 | (3) Create three string variables with values “I love eating“, “veggies”, “fruits” 48 | (a) Print “I love eating veggies and fruits” (Hint: Use + operator) 49 | >>> s1="I love eating" 50 | >>> s2="veggies" 51 | >>> s3="fruits" 52 | >>> s1+" " +s2+" and "+s3 53 | 'I love eating veggies and fruits' 54 | (b) Create fourth variable to store number of fruits you eat everyday. Say for example you eat 2 fruits everyday, in that case print “I love eating 2 fruits everyday” 55 | >>> num_fruits=2 56 | >>> s1+" "+str(num_fruits)+" "+s3+" everyday" 57 | 'I love eating 2 fruits everyday' 58 | -------------------------------------------------------------------------------- /DataStructures/3_LinkedList/3_linked_list_exercise.md: -------------------------------------------------------------------------------- 1 | # Exercise: Linked List 2 | 3 | 1. In [LinkedList class](https://github.com/codebasics/py/blob/master/DataStructures/3_LinkedList/3_linked_list.py) that we implemented in our tutorial add following two methods, 4 | ``` 5 | def insert_after_value(self, data_after, data_to_insert): 6 | # Search for first occurance of data_after value in linked list 7 | # Now insert data_to_insert after data_after node 8 | 9 | def remove_by_value(self, data): 10 | # Remove first node that contains data 11 | ``` 12 | Now make following calls, 13 | ``` 14 | ll = LinkedList() 15 | ll.insert_values(["banana","mango","grapes","orange"]) 16 | ll.print() 17 | ll.insert_after_value("mango","apple") # insert apple after mango 18 | ll.print() 19 | ll.remove_by_value("orange") # remove orange from linked list 20 | ll.print() 21 | ll.remove_by_value("figs") 22 | ll.print() 23 | ll.remove_by_value("banana") 24 | ll.remove_by_value("mango") 25 | ll.remove_by_value("apple") 26 | ll.remove_by_value("grapes") 27 | ll.print() 28 | ``` 29 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/3_LinkedList/Solution/singly_linked_list_exercise.py) 30 | 31 | 2. Implement doubly linked list. The only difference with regular linked list is that double linked has prev node reference as well. That way you can iterate in forward and backward direction. 32 | Your node class will look this this, 33 | ``` 34 | class Node: 35 | def __init__(self, data=None, next=None, prev=None): 36 | self.data = data 37 | self.next = next 38 | self.prev = prev 39 | ``` 40 | Add following new methods, 41 | ``` 42 | def print_forward(self): 43 | # This method prints list in forward direction. Use node.next 44 | 45 | def print_backward(self): 46 | # Print linked list in reverse direction. Use node.prev for this. 47 | ``` 48 | Implement all other methods in [regular linked list class](https://github.com/codebasics/py/blob/master/DataStructures/3_LinkedList/3_linked_list.py) and make necessary changes for doubly linked list (you need to populate node.prev in all those methods) 49 | 50 | [Solution](https://github.com/codebasics/py/blob/master/DataStructures/3_LinkedList/Solution/doubly_linked_list_exercise.py) -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/client/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Banglore Home Price Prediction 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 |

Area (Square Feet)

13 | 14 |

BHK

15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 |

Bath

30 |
31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 |

Location

43 |
44 | 49 |
50 | 51 |

52 | 53 | 54 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/client/app.js: -------------------------------------------------------------------------------- 1 | function getBathValue() { 2 | var uiBathrooms = document.getElementsByName("uiBathrooms"); 3 | for(var i in uiBathrooms) { 4 | if(uiBathrooms[i].checked) { 5 | return parseInt(i)+1; 6 | } 7 | } 8 | return -1; // Invalid Value 9 | } 10 | 11 | function getBHKValue() { 12 | var uiBHK = document.getElementsByName("uiBHK"); 13 | for(var i in uiBHK) { 14 | if(uiBHK[i].checked) { 15 | return parseInt(i)+1; 16 | } 17 | } 18 | return -1; // Invalid Value 19 | } 20 | 21 | function onClickedEstimatePrice() { 22 | console.log("Estimate price button clicked"); 23 | var sqft = document.getElementById("uiSqft"); 24 | var bhk = getBHKValue(); 25 | var bathrooms = getBathValue(); 26 | var location = document.getElementById("uiLocations"); 27 | var estPrice = document.getElementById("uiEstimatedPrice"); 28 | 29 | // var url = "http://127.0.0.1:5000/predict_home_price"; Use this if you are NOT using nginx which is first 7 tutorials 30 | var url = "/api/predict_home_price"; // Use this if you are using nginx. i.e tutorial 8 and onwards 31 | 32 | $.post(url, { 33 | total_sqft: parseFloat(sqft.value), 34 | bhk: bhk, 35 | bath: bathrooms, 36 | location: location.value 37 | },function(data, status) { 38 | console.log(data.estimated_price); 39 | estPrice.innerHTML = "

" + data.estimated_price.toString() + " Lakh

"; 40 | console.log(status); 41 | }); 42 | } 43 | 44 | function onPageLoad() { 45 | console.log( "document loaded" ); 46 | // var url = "http://127.0.0.1:5000/get_location_names"; // Use this if you are NOT using nginx which is first 7 tutorials 47 | var url = "/api/get_location_names"; // Use this if you are using nginx. i.e tutorial 8 and onwards 48 | $.get(url,function(data, status) { 49 | console.log("got response for get_location_names request"); 50 | if(data) { 51 | var locations = data.locations; 52 | var uiLocations = document.getElementById("uiLocations"); 53 | $('#uiLocations').empty(); 54 | for(var i in locations) { 55 | var opt = new Option(locations[i]); 56 | $('#uiLocations').append(opt); 57 | } 58 | } 59 | }); 60 | } 61 | 62 | window.onload = onPageLoad; -------------------------------------------------------------------------------- /pandas/4_read_write_to_excel/read_write_with_flask/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple tables 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | {% for table in tables %} 15 |

{{titles[loop.index]}}

16 | {{ table|safe }} 17 | {% endfor %} 18 |
19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 48 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Basics/for.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ============ Exercises =============== # 4 | def ex_expense_break(): 5 | """ 6 | Your monthly expense list (from Jan to May) looks like this, 7 | expense_list = [2340, 2500, 2100, 3100, 2980] 8 | Write a program that asks you to enter an expense amount and program 9 | should tell you in which month that expense occurred. 10 | """ 11 | 12 | month_list = ["January", "February", "March", "April", "May"] 13 | expense_list = [2340, 2500, 2100, 3100, 2980] 14 | e = input("Enter expense amount: ") 15 | e = int(e) 16 | 17 | month = -1 18 | for i in range(len(expense_list)): 19 | if e == expense_list[i]: 20 | month = i 21 | break 22 | 23 | if month != -1: 24 | print('You spent',e,'in',month_list[month]) 25 | else: 26 | print('You didn\'t spend',e,'in any month') 27 | 28 | 29 | def ex_print_shape(): 30 | """ 31 | Write a program that prints following shape 32 | * 33 | ** 34 | *** 35 | **** 36 | ***** 37 | """ 38 | for i in range(1,6): 39 | s = '' 40 | for j in range(i): 41 | s += '*' 42 | print(s) 43 | 44 | 45 | def ex_heads_tails(): 46 | """ 47 | After flipping a coin 10 times you got this result, 48 | result = ["heads","tails","tails","heads","tails","heads","heads","tails","tails","tails"] 49 | Using for loop figure out “heads” count. 50 | """ 51 | result = ["heads","tails","tails","heads","tails","heads","heads","tails","tails","tails"] 52 | count = 0 53 | for item in result: 54 | if item == "heads": 55 | count += 1 56 | print("Heads count: ",count) 57 | 58 | 59 | # ============ Demo =============== # 60 | def demo_break_marathon(): 61 | """break demo using running race""" 62 | for i in range(26): 63 | print("You ran",i+1,"miles.") # i starts with zero hence adding 1 64 | tired = input("Are you tired? ") 65 | if tired == 'yes': 66 | break 67 | 68 | if i == 26: 69 | print("Hurray! You are a rock star! You just finished marathon!") 70 | else: 71 | print("You didn't finish marathon but hey congrats anyways! You still ran", i+1,"miles") 72 | 73 | 74 | def demo_continue(): 75 | """Print square of all numbers between 1 to 10 except even numbers""" 76 | for i in range(1,11): 77 | if i % 2 == 0: 78 | continue 79 | print(i*i) 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /Basics/functions.py: -------------------------------------------------------------------------------- 1 | def print_pattern(n=5): 2 | ''' 3 | :param n: Integer number representing number of lines 4 | to be printed in a pattern. If n=3 it will print, 5 | * 6 | ** 7 | *** 8 | If n=4, it will print, 9 | * 10 | ** 11 | *** 12 | **** 13 | Default value for n is 5. So if function caller doesn't 14 | supply the input number then it will assume it to be 5 15 | :return: None 16 | ''' 17 | # we need to run two for loops. Outer loop prints patterns line by line 18 | # where as inner loop print the content of that specific lines 19 | for i in range(n): 20 | s = '' 21 | for j in range(i+1): 22 | s = s + '*' 23 | print(s) 24 | 25 | def calculate_area(dimension1,dimension2,shape="triangle"): 26 | ''' 27 | :param dimension1: In case of triangle it is "base". For rectangle it is "length". 28 | :param dimension2: In case of triangle it is "height". For rectangle it is "width". 29 | :param shape: Either "triangle" or "rectangle" 30 | :return: Area of a shape 31 | ''' 32 | if shape=="triangle": 33 | area=1/2*(dimension1*dimension2) # Triangle area is : 1/2(Base*Height) 34 | elif shape=="rectangle": 35 | area=dimension1*dimension2 # Rectangle area is: Length*Width 36 | else: 37 | print("***Error: Input shape is neither triangle nor rectangle.") 38 | area=None # If user didn't supply "triangle" or "rectangle" as shape then return None 39 | return area 40 | 41 | # ------------------ Shape area exercise ------------------------- # 42 | # Calculate area of triangle whose base is 10 and height is 5 43 | base=10 44 | height=5 45 | triangle_area=calculate_area(base,height,"triangle") 46 | print("Area of triangle is:",triangle_area) 47 | 48 | # Calculate area of a rectangle whose length is 20 and width is 30 49 | length=20 50 | width=30 51 | rectangle_area=calculate_area(length,width,"rectangle") 52 | print("Area of rectangle is:",rectangle_area) 53 | 54 | # Calculate area of a triangle without supplying shape argument in a function call 55 | triangle_area=calculate_area(base,height) # Here third argument is missing 56 | print("Area of triangle with no shape supplied: ",triangle_area) 57 | 58 | # -------------------- Pattern exercise ------------------------- # 59 | print("Print pattern with input=3") 60 | print_pattern(3) 61 | print("Print pattern with input=4") 62 | print_pattern(4) 63 | print("Print pattern with no input number") 64 | print_pattern() # Not supplying any input will use default argument which is 5 65 | 66 | 67 | -------------------------------------------------------------------------------- /pandas/1_intro/pandas_intro.py: -------------------------------------------------------------------------------- 1 | # This program shows that without using pandas getting answers on below questions is hard and not convinient 2 | # (1) Max temperature in New York in month of January 3 | # (2) List of days when it rained 4 | # (3) Average speed of wind in month of january 5 | __parsed_rows = [] 6 | 7 | def parse_csv(): 8 | import csv 9 | __file_path = "nyc_weather.csv" 10 | __index = { 11 | 'date': 0, 12 | 'temperature': 1, 13 | 'DewPoint': 2, 14 | 'Humidity': 3, 15 | 'Sea_Level_PressureIn': 4, 16 | 'VisibilityMiles': 5, 17 | 'WindSpeedMPH': 6, 18 | 'PrecipitationIn': 7, 19 | 'CloudCover': 8, 20 | 'Events' : 9, 21 | 'WindDirDegrees': 10 22 | } 23 | 24 | global __parsed_rows 25 | with open(__file_path, "r") as f: 26 | reader = csv.reader(f) 27 | next(reader, None) 28 | for row in reader: 29 | __parsed_rows.append({ 30 | 'date': row[__index['date']], 31 | 'temperature': row[__index['temperature']], 32 | 'DewPoint': row[__index['DewPoint']], 33 | 'Humidity': row[__index['Humidity']], 34 | 'Sea_Level_PressureIn': row[__index['Sea_Level_PressureIn']], 35 | 'VisibilityMiles': row[__index['VisibilityMiles']], 36 | 'WindSpeedMPH': row[__index['WindSpeedMPH']], 37 | 'PrecipitationIn': row[__index['PrecipitationIn']], 38 | 'CloudCover': row[__index['CloudCover']], 39 | 'Events': row[__index['Events']], 40 | 'WindDirDegrees': row[__index['WindDirDegrees']] 41 | }) 42 | 43 | 44 | def get_days_for_event(event_name): 45 | days = [] 46 | for row in __parsed_rows: 47 | if row['Events'] == event_name: 48 | days.append(row['date']) 49 | return days 50 | 51 | def get_max_temperature(): 52 | max_temp = 0 53 | for row in __parsed_rows: 54 | if int(row['temperature']) > max_temp: 55 | max_temp = int(row['temperature']) 56 | return max_temp 57 | 58 | def get_average_wind_speed(): 59 | total = 0 60 | count = 0 61 | for row in __parsed_rows: 62 | speed = 0 if row['WindSpeedMPH']=='' else int(row['WindSpeedMPH']) 63 | total += speed 64 | count+=1 65 | return total/count 66 | 67 | if __name__=="__main__": 68 | parse_csv() 69 | 70 | print("Max temperature is: ",get_max_temperature()) 71 | print ("Days of rain: ", get_days_for_event('Rain')) 72 | print("Average wind speed is: ", get_average_wind_speed()) 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Basics/Hindi/7_for/Exercise/7_for_exercise.py: -------------------------------------------------------------------------------- 1 | # ## Exercise: Python for loop 2 | # 1. After flipping a coin 10 times you got this result, 3 | # ``` 4 | # result = ["heads","tails","tails","heads","tails","heads","heads","tails","tails","tails"] 5 | # ``` 6 | # Using for loop figure out how many times you got heads 7 | print("\nExercise 1\n") 8 | result = ["heads","tails","tails","heads","tails","heads","heads","tails","tails","tails"] 9 | count = 0 10 | for item in result: 11 | if item == "heads": 12 | count += 1 13 | print("Heads count: ",count) 14 | 15 | 16 | # 2. Print square of all numbers between 1 to 10 except even numbers 17 | print("\nExercise 2\n") 18 | for i in range(1,11): 19 | if i % 2 == 0: 20 | continue 21 | print(i*i) 22 | 23 | # 3. Your monthly expense list (from Jan to May) looks like this, 24 | # ``` 25 | # expense_list = [2340, 2500, 2100, 3100, 2980] 26 | # ``` 27 | # Write a program that asks you to enter an expense amount and program 28 | # should tell you in which month that expense occurred. If expense is not 29 | # found then it should print that as well. 30 | print("\nExercise 3\n") 31 | month_list = ["January", "February", "March", "April", "May"] 32 | expense_list = [2340, 2500, 2100, 3100, 2980] 33 | e = input("Enter expense amount: ") 34 | e = int(e) 35 | 36 | month = -1 37 | for i in range(len(expense_list)): 38 | if e == expense_list[i]: 39 | month = i 40 | break 41 | 42 | if month != -1: 43 | print(f'You spent {e} in {month_list[month]}') 44 | else: 45 | print(f'You didn\'t spend {e} in any month') 46 | 47 | # 4. Lets say you are running a 5 km race. Write a program that, 48 | # 1. Upon completing each 1 km asks you "are you tired?" 49 | # 2. If you reply "yes" then it should break and print "you didn't finish the race" 50 | # 3. If you reply "no" then it should continue and ask "are you tired" on every km 51 | # 4. If you finish all 5 km then it should print congratulations message 52 | 53 | print("\nExercise 4\n") 54 | 55 | for i in range(5): 56 | print(f"You ran {i+1} miles") # i starts with zero hence adding 1 57 | tired = input("Are you tired? ") 58 | if tired == 'yes': 59 | break 60 | 61 | if i == 4: # 4 because the index starts from 0 62 | print("Hurray! You are a rock star! You just finished 5 km race!") 63 | else: 64 | print("You didn't finish 5 km race but hey congrats anyways! You still ran {i+1} miles") 65 | 66 | # 5. Write a program that prints following shape 67 | # ``` 68 | # * 69 | # ** 70 | # *** 71 | # **** 72 | # ***** 73 | # ``` 74 | print("\nExercise 5\n") 75 | 76 | for i in range(1,6): 77 | s = '' 78 | for j in range(i): 79 | s += '*' 80 | print(s) -------------------------------------------------------------------------------- /DataStructures/3_LinkedList/3_linked_list.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data=None, next=None): 3 | self.data = data 4 | self.next = next 5 | 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | 10 | def print(self): 11 | if self.head is None: 12 | print("Linked list is empty") 13 | return 14 | itr = self.head 15 | llstr = '' 16 | while itr: 17 | llstr += str(itr.data) + ' --> ' 18 | itr = itr.next 19 | print(llstr) 20 | 21 | def get_length(self): 22 | count = 0 23 | itr = self.head 24 | while itr: 25 | count+=1 26 | itr = itr.next 27 | 28 | return count 29 | 30 | def insert_at_begining(self, data): 31 | node = Node(data, self.head) 32 | self.head = node 33 | 34 | def insert_at_end(self, data): 35 | if self.head is None: 36 | self.head = Node(data, None) 37 | return 38 | 39 | itr = self.head 40 | 41 | while itr.next: 42 | itr = itr.next 43 | 44 | itr.next = Node(data, None) 45 | 46 | def insert_at(self, index, data): 47 | if index<0 or index>self.get_length(): 48 | raise Exception("Invalid Index") 49 | 50 | if index==0: 51 | self.insert_at_begining(data) 52 | return 53 | 54 | count = 0 55 | itr = self.head 56 | while itr: 57 | if count == index - 1: 58 | node = Node(data, itr.next) 59 | itr.next = node 60 | break 61 | 62 | itr = itr.next 63 | count += 1 64 | 65 | def remove_at(self, index): 66 | if index<0 or index>=self.get_length(): 67 | raise Exception("Invalid Index") 68 | 69 | if index==0: 70 | self.head = self.head.next 71 | return 72 | 73 | count = 0 74 | itr = self.head 75 | while itr: 76 | if count == index - 1: 77 | itr.next = itr.next.next 78 | break 79 | 80 | itr = itr.next 81 | count+=1 82 | 83 | def insert_values(self, data_list): 84 | self.head = None 85 | for data in data_list: 86 | self.insert_at_end(data) 87 | 88 | 89 | if __name__ == '__main__': 90 | ll = LinkedList() 91 | ll.insert_values(["banana","mango","grapes","orange"]) 92 | ll.insert_at(1,"blueberry") 93 | ll.remove_at(2) 94 | ll.print() 95 | 96 | ll.insert_values([45,7,12,567,99]) 97 | ll.insert_at_end(67) 98 | ll.print() 99 | 100 | -------------------------------------------------------------------------------- /Basics/Hindi/5_lists/Exercise/5_lists_exercise.py: -------------------------------------------------------------------------------- 1 | # 1. Let us say your expense for every month are listed below, 2 | # 1. January - 2200 3 | # 2. February - 2350 4 | # 3. March - 2600 5 | # 4. April - 2130 6 | # 5. May - 2190 7 | # 8 | # Create a list to store these monthly expenses and using that find out, 9 | # 10 | # 1. In Feb, how many dollars you spent extra compare to January? 11 | # 2. Find out your total expense in first quarter (first three months) of the year. 12 | # 3. Find out if you spent exactly 2000 dollars in any month 13 | # 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 14 | # 5. You returned an item that you bought in a month of April and 15 | # got a refund of 200$. Make a correction to your monthly expense list 16 | # based on this 17 | 18 | exp = [2200,2350,2600,2130,2190] 19 | 20 | # 1. In Feb, how many dollars you spent extra compare to January? 21 | print("In feb this much extra was spent compared to jan:",exp[1]-exp[0]) # 150 22 | 23 | # 2. Find out your total expense in first quarter (first three months) of the year 24 | print("Expense for first quarter:",exp[0]+exp[1]+exp[2]) # 7150 25 | 26 | # 3. Find out if you spent exactly 2000 dollars in any month 27 | print("Did I spent 2000$ in any month? ", 2000 in exp) # False 28 | 29 | # 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list 30 | exp.append(1980) 31 | print("Expenses at the end of June:",exp) # [2200, 2350, 2600, 2130, 2190, 1980] 32 | 33 | # 5. You returned an item that you bought in a month of April and 34 | # got a refund of 200$. Make a correction to your monthly expense list 35 | # based on this 36 | exp[3] = exp[3] - 200 37 | print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190, 1980] 38 | 39 | # 2. You have a list of your favourite marvel super heros 40 | # heros=['spider man','thor','hulk','iron man','captain america'] 41 | # Using this list 42 | 43 | heros=['spider man','thor','hulk','iron man','captain america'] 44 | # 1. Length of the list 45 | print(len(heros)) 46 | # 2. Add 'black panther' at the end of this list 47 | heros.append('black panther') 48 | print(heros) 49 | # 3. You realize that you need to add 'black panther' after 'hulk', 50 | # so remove it from the list first and then add it after 'hulk' 51 | heros.remove('black panther') 52 | heros.insert(3,'black panther') 53 | print(heros) 54 | # 4. Now you don't like thor and hulk because they get angry easily :) 55 | # So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool). 56 | # Do that with one line of code. 57 | heros[1:3]=['doctor strange'] 58 | print(heros) 59 | # 5. Sort the list in alphabetical order 60 | heros.sort() 61 | print(heros) 62 | -------------------------------------------------------------------------------- /TechTopics/HowToLearnProgramming/how_to_learn_programming.md: -------------------------------------------------------------------------------- 1 | # Step by step guide on how you can learn programming 2 | 3 | Below is the 11 step process of how you can start with zero knowledge and no computer science background and master coding skills 4 | 5 | ### Step 1. Understand principals of effective learning 6 | 7 | Please watch this video to understand how you can learn effectively so that you can get maximum output by investing minimum amount of time. 8 | 9 | https://www.youtube.com/watch?v=ZVO8Wt_PCgE 10 | 11 | Quick summary of this video is in the image below, 12 | 13 | ![Effective Learning](nishant_effective_learning.png) 14 | 15 | Here nishant talks about spending less time in input (which is watching coding tutorials, reading programming books etc) and spending more time in reflecting, practicing coding problems and sharing with your friends. 16 | 17 | ### Step 2. What is Code? 18 | 19 | At this step you want to understand what exactly is code. It is a language that you use to communicate with the computer (hence it is called programming ***language***). This video goes elaborates what exactly is code. 20 | 21 | https://www.youtube.com/watch?v=hYws-CDXA7k 22 | 23 | ### Step 3. Computer Science Principals 24 | 25 | Program or code runs on a computer and uses CPU,RAM, input/output devices. This khan academy course goes over all these basic principals of computer science. Data is stored as bits (1s and 0s) in RAM and disk. The course will also go over fundamentals of binary numbers. 26 | 27 | https://www.khanacademy.org/computing/ap-computer-science-principles/computers-101 28 | 29 | ### Step 4. Choose Career Track 30 | 31 | Being programmer is like being a doctor where there are many different specializations. Doctor can be a heart specialist, a lung doctor 32 | or a general physician. Similarly you can become a web programmer, mobile app developer or backend developer. Here I have outlined 33 | few popular career tracks along with programming languages required for that particular career track, 34 | 35 | 1. Web Development 36 | 1. HTML/CSS/Javascript - Holy trinity of web programming 37 | 1. Frameworks: node js, react js, vue js etc 38 | 1. Mobile App Development 39 | 1. HTML/CSS/Javascript 40 | 1. Native Apps 41 | 1. IOS: Swift programming language 42 | 1. Android: JAVA 43 | 1. Hybrid Apps 44 | 1. React Native 45 | 1. Flutter 46 | 1. Data Science, Machine Learning, Backend Development 47 | 1. Python 48 | 1. JAVA 49 | 50 | ### Step 5. Level 1 Coding Tutorials 51 | 52 | At this stage you are ready to write your first program and explore coding tutorials. The idea is to get basic understanding 53 | of programming such as variables, data types, file operation, writing static web pages etc. Below is information on courses 54 | based on career track, 55 | 56 | 1. Web and mobile app development 57 | 58 | 1. Data science, backend development 59 | 60 | -------------------------------------------------------------------------------- /pandas/1_intro/Pandas_introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import pandas as pd\n", 12 | "df = pd.read_csv('nyc_weather.csv')\n", 13 | "df" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 66, 19 | "metadata": { 20 | "collapsed": false 21 | }, 22 | "outputs": [ 23 | { 24 | "data": { 25 | "text/plain": [ 26 | "50" 27 | ] 28 | }, 29 | "execution_count": 66, 30 | "metadata": {}, 31 | "output_type": "execute_result" 32 | } 33 | ], 34 | "source": [ 35 | "df['Temperature'].max()" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 67, 41 | "metadata": { 42 | "collapsed": false, 43 | "scrolled": true 44 | }, 45 | "outputs": [ 46 | { 47 | "data": { 48 | "text/plain": [ 49 | "8 1/9/2016\n", 50 | "9 1/10/2016\n", 51 | "15 1/16/2016\n", 52 | "26 1/27/2016\n", 53 | "Name: EST, dtype: object" 54 | ] 55 | }, 56 | "execution_count": 67, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "df['EST'][df['Events']=='Rain']" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 69, 68 | "metadata": { 69 | "collapsed": false 70 | }, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "6.225806451612903" 76 | ] 77 | }, 78 | "execution_count": 69, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "df.fillna(0, inplace=True)\n", 85 | "df['WindSpeedMPH'].mean()" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": { 92 | "collapsed": true 93 | }, 94 | "outputs": [], 95 | "source": [] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": { 101 | "collapsed": true 102 | }, 103 | "outputs": [], 104 | "source": [] 105 | } 106 | ], 107 | "metadata": { 108 | "anaconda-cloud": {}, 109 | "kernelspec": { 110 | "display_name": "Python [conda root]", 111 | "language": "python", 112 | "name": "conda-root-py" 113 | }, 114 | "language_info": { 115 | "codemirror_mode": { 116 | "name": "ipython", 117 | "version": 3 118 | }, 119 | "file_extension": ".py", 120 | "mimetype": "text/x-python", 121 | "name": "python", 122 | "nbconvert_exporter": "python", 123 | "pygments_lexer": "ipython3", 124 | "version": "3.5.2" 125 | } 126 | }, 127 | "nbformat": 4, 128 | "nbformat_minor": 1 129 | } 130 | -------------------------------------------------------------------------------- /Basics/Hindi/11_dict_tuple/11_dict_tuple_exercise.md: -------------------------------------------------------------------------------- 1 | ## Exercise: Python Dict and Tuples 2 | 3 | 1. We have following information on countries and their population (population is in crores), 4 | 5 | |Country|Population| 6 | |-------|----------| 7 | |China|143| 8 | |India|136| 9 | |USA|32| 10 | |Pakistan|21| 11 | 1. Using above create a dictionary of countries and its population 12 | 2. Write a program that asks user for three type of inputs, 13 | 1. print: if user enter print then it should print all countries with their population in this format, 14 | ``` 15 | china==>143 16 | india==>136 17 | usa==>32 18 | pakistan==>21 19 | ``` 20 | 1. add: if user input add then it should further ask for a country name to add. If country already exist in our dataset then it should print that it exist and do nothing. If it doesn't then it asks for population and add that new country/population in our dictionary and print it 21 | 2. remove: when user inputs remove it should ask for a country to remove. If country exist in our dictionary then remove it and print new dictionary using format shown above in (a). Else print that country doesn't exist! 22 | 3. query: on this again ask user for which country he or she wants to query. When user inputs that country it will print population of that country. 23 | 24 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_1_country_population.py) 25 | 26 | 2. You are given following list of stocks and their prices in last 3 days, 27 | 28 | |Stock|Prices| 29 | |-------|----------| 30 | |info|[600,630,620]| 31 | |ril|[1430,1490,1567]| 32 | |mtl|[234,180,160]| 33 | 34 | 1. Write a program that asks user for operation. Value of operations could be, 35 | 1. print: When user enters print it should print following, 36 | ``` 37 | info ==> [600, 630, 620] ==> avg: 616.67 38 | ril ==> [1430, 1490, 1567] ==> avg: 1495.67 39 | mtl ==> [234, 180, 160] ==> avg: 191.33 40 | ``` 41 | 2. add: When user enters 'add', it asks for stock ticker and price. If stock already exist in your list (like info, ril etc) then it will append the price to the list. Otherwise it will create new entry in your dictionary. For example entering 'tata' and 560 will add tata ==> [560] to the dictionary of stocks. 42 | 43 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_2_stocks.py) 44 | 45 | 3. Write circle_calc() function that takes radius of a circle as an input from user and then it calculates and returns area, circumference and diameter. You should get these values in your main program by calling circle_calc function and then print them 46 | 47 | [Solution](https://github.com/codebasics/py/blob/master/Basics/Hindi/11_dict_tuple/Exercise/11_dict_exercise_3_circle.py) -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/client/app.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Roboto:300); 2 | 3 | .switch-field { 4 | display: flex; 5 | margin-bottom: 36px; 6 | overflow: hidden; 7 | } 8 | 9 | .switch-field input { 10 | position: absolute !important; 11 | clip: rect(0, 0, 0, 0); 12 | height: 1px; 13 | width: 1px; 14 | border: 0; 15 | overflow: hidden; 16 | } 17 | 18 | .switch-field label { 19 | background-color: #e4e4e4; 20 | color: rgba(0, 0, 0, 0.6); 21 | font-size: 14px; 22 | line-height: 1; 23 | text-align: center; 24 | padding: 8px 16px; 25 | margin-right: -1px; 26 | border: 1px solid rgba(0, 0, 0, 0.2); 27 | box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1); 28 | transition: all 0.1s ease-in-out; 29 | } 30 | 31 | .switch-field label:hover { 32 | cursor: pointer; 33 | } 34 | 35 | .switch-field input:checked + label { 36 | background-color: #a5dc86; 37 | box-shadow: none; 38 | } 39 | 40 | .switch-field label:first-of-type { 41 | border-radius: 4px 0 0 4px; 42 | } 43 | 44 | .switch-field label:last-of-type { 45 | border-radius: 0 4px 4px 0; 46 | } 47 | 48 | .form { 49 | max-width: 270px; 50 | font-family: "Lucida Grande", Tahoma, Verdana, sans-serif; 51 | font-weight: normal; 52 | line-height: 1.625; 53 | margin: 8px auto; 54 | padding-left: 16px; 55 | z-index: 2; 56 | } 57 | 58 | h2 { 59 | font-size: 18px; 60 | margin-bottom: 8px; 61 | } 62 | .area{ 63 | font-family: "Roboto", sans-serif; 64 | outline: 0; 65 | background: #f2f2f2; 66 | width: 76%; 67 | border: 0; 68 | margin: 0 0 10px; 69 | padding: 10px; 70 | box-sizing: border-box; 71 | font-size: 15px; 72 | height: 35px; 73 | border-radius: 5px; 74 | } 75 | 76 | .location{ 77 | font-family: "Roboto", sans-serif; 78 | outline: 0; 79 | background: #f2f2f2; 80 | width: 76%; 81 | border: 0; 82 | margin: 0 0 10px; 83 | padding: 10px; 84 | box-sizing: border-box; 85 | font-size: 15px; 86 | height: 40px; 87 | border-radius: 5px; 88 | } 89 | 90 | .submit{ 91 | background: #a5dc86; 92 | width: 76%; 93 | border: 0; 94 | margin: 25px 0 10px; 95 | box-sizing: border-box; 96 | font-size: 15px; 97 | height: 35px; 98 | text-align: center; 99 | border-radius: 5px; 100 | } 101 | 102 | .result{ 103 | background: #dcd686; 104 | width: 76%; 105 | border: 0; 106 | margin: 25px 0 10px; 107 | box-sizing: border-box; 108 | font-size: 15px; 109 | height: 35px; 110 | text-align: center; 111 | } 112 | 113 | .img { 114 | background: url('https://images.unsplash.com/photo-1564013799919-ab600027ffc6?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80'); 115 | background-repeat: no-repeat; 116 | background-size: auto; 117 | background-size:100% 100%; 118 | -webkit-filter: blur(5px); 119 | -moz-filter: blur(5px); 120 | -o-filter: blur(5px); 121 | -ms-filter: blur(5px); 122 | filter: blur(15px); 123 | position: fixed; 124 | width: 100%; 125 | height: 100%; 126 | top: 0; 127 | left: 0; 128 | z-index: -1; 129 | } 130 | 131 | body, html { 132 | height: 100%; 133 | } -------------------------------------------------------------------------------- /Basics/Hindi/1_Variables/Exercise/1_variables_exercise.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "**1. Create a variable called break and assign it a value 5. See what happens and find out the reason behind the behavior that you see**" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 5, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "ename": "SyntaxError", 19 | "evalue": "invalid syntax (, line 1)", 20 | "output_type": "error", 21 | "traceback": [ 22 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m break=5\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "break=5" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "**2. Create two variables. One to store your birth year and another one to store current year. Now calculate your age using these two variables**" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": { 41 | "scrolled": true 42 | }, 43 | "outputs": [], 44 | "source": [ 45 | "birth_year=1982\n", 46 | "current_year=2019\n", 47 | "age=current_year-birth_year\n", 48 | "age" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "**3. Store your first, middle and last name in three different variables and then print your full name using these variables**" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 6, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "My full name is: Dhaval Rambhai Patel\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "first=\"Dhaval\"\n", 73 | "middle=\"Rambhai\"\n", 74 | "last=\"Patel\"\n", 75 | "print(\"My full name is: \" + first + \" \" + middle + \" \" + last)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "**4. Answer which of these are invalid variable names: \"\\_nation, 1record, record1, record\\_one, record-one, record^one, continue\"**" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "1record, record-one, record^one, continue" 90 | ] 91 | } 92 | ], 93 | "metadata": { 94 | "kernelspec": { 95 | "display_name": "Python 3", 96 | "language": "python", 97 | "name": "python3" 98 | }, 99 | "language_info": { 100 | "codemirror_mode": { 101 | "name": "ipython", 102 | "version": 3 103 | }, 104 | "file_extension": ".py", 105 | "mimetype": "text/x-python", 106 | "name": "python", 107 | "nbconvert_exporter": "python", 108 | "pygments_lexer": "ipython3", 109 | "version": "3.7.3" 110 | } 111 | }, 112 | "nbformat": 4, 113 | "nbformat_minor": 2 114 | } 115 | -------------------------------------------------------------------------------- /Basics/Hindi/8_functions/Exercise/8_functions_exercise.py: -------------------------------------------------------------------------------- 1 | def print_pattern(n=5): 2 | ''' 3 | :param n: Integer number representing number of lines 4 | to be printed in a pattern. If n=3 it will print, 5 | * 6 | ** 7 | *** 8 | If n=4, it will print, 9 | * 10 | ** 11 | *** 12 | **** 13 | Default value for n is 5. So if function caller doesn't 14 | supply the input number then it will assume it to be 5 15 | :return: None 16 | ''' 17 | # we need to run two for loops. Outer loop prints patterns line by line 18 | # where as inner loop print the content of that specific lines 19 | for i in range(n): 20 | s = '' 21 | for j in range(i+1): 22 | s = s + '*' 23 | print(s) 24 | 25 | def calculate_area(dimension1,dimension2,shape="triangle"): 26 | ''' 27 | :param dimension1: In case of triangle it is "base". For rectangle it is "length". 28 | :param dimension2: In case of triangle it is "height". For rectangle it is "width". 29 | :param shape: Either "triangle" or "rectangle" 30 | :return: Area of a shape 31 | ''' 32 | if shape=="triangle": 33 | area=1/2*(dimension1*dimension2) # Triangle area is : 1/2(Base*Height) 34 | elif shape=="rectangle": 35 | area=dimension1*dimension2 # Rectangle area is: Length*Width 36 | else: 37 | print("Error: Input shape is neither triangle nor rectangle.") 38 | area=None # If user didn't supply "triangle" or "rectangle" as shape then return None 39 | return area 40 | 41 | 42 | # 1. Write a function called calculate_area that takes base and height as an input and returns and area of a triangle. Equation of an area of a triangle is, 43 | # ``` 44 | # area = (1/2)*base*height 45 | # ``` 46 | # 47 | # 2. Modify above function to take third parameter shape type. It can be either "triangle" or "rectangle". Based on shape type it will calculate area. Equation of rectangle's area is, 48 | # ``` 49 | # rectangle area=length*width 50 | # ``` 51 | # If no shape is supplied then it should take triangle as a default shape 52 | 53 | # Calculate area of triangle whose base is 10 and height is 5 54 | base=10 55 | height=5 56 | triangle_area=calculate_area(base,height,"triangle") 57 | print("Area of triangle is:",triangle_area) 58 | 59 | # Calculate area of a rectangle whose length is 20 and width is 30 60 | length=20 61 | width=30 62 | rectangle_area=calculate_area(length,width,"rectangle") 63 | print("Area of rectangle is:",rectangle_area) 64 | 65 | # Calculate area of a triangle without supplying shape argument in a function call 66 | triangle_area=calculate_area(base,height) # Here third argument is missing 67 | print("Area of triangle with no shape supplied: ",triangle_area) 68 | 69 | 70 | # 3. Write a function called print_pattern that takes integer number as an argument and prints following pattern if input number is 3, 71 | # ``` 72 | # * 73 | # ** 74 | # *** 75 | # ``` 76 | # if input is 4 then it should print 77 | # ``` 78 | # * 79 | # ** 80 | # *** 81 | # **** 82 | # ``` 83 | # Basically number of lines it prints is equal to that number. (Hint: you need to use two for loops) 84 | 85 | print("Print pattern with input=3") 86 | print_pattern(3) 87 | print("Print pattern with input=4") 88 | print_pattern(4) 89 | print("Print pattern with no input number") 90 | print_pattern() # Not supplying any input will use default argument which is 5 -------------------------------------------------------------------------------- /DataStructures/3_LinkedList/Solution/doubly_linked_list_exercise.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data=None, next=None, prev=None): 3 | self.data = data 4 | self.next = next 5 | self.prev = prev 6 | 7 | class DoublyLinkedList: 8 | def __init__(self): 9 | self.head = None 10 | 11 | def print_forward(self): 12 | if self.head is None: 13 | print("Linked list is empty") 14 | return 15 | 16 | itr = self.head 17 | llstr = '' 18 | while itr: 19 | llstr += str(itr.data) + ' --> ' 20 | itr = itr.next 21 | print(llstr) 22 | 23 | def print_backward(self): 24 | if self.head is None: 25 | print("Linked list is empty") 26 | return 27 | 28 | last_node = self.get_last_node() 29 | itr = last_node 30 | llstr = '' 31 | while itr: 32 | llstr += itr.data + '-->' 33 | itr = itr.prev 34 | print("Link list in reverse: ", llstr) 35 | 36 | def get_last_node(self): 37 | itr = self.head 38 | while itr.next: 39 | itr = itr.next 40 | 41 | return itr 42 | 43 | def get_length(self): 44 | count = 0 45 | itr = self.head 46 | while itr: 47 | count+=1 48 | itr = itr.next 49 | 50 | return count 51 | 52 | def insert_at_begining(self, data): 53 | node = Node(data, self.head, None) 54 | self.head.prev = node 55 | self.head = node 56 | 57 | def insert_at_end(self, data): 58 | if self.head is None: 59 | self.head = Node(data, None, None) 60 | return 61 | 62 | itr = self.head 63 | 64 | while itr.next: 65 | itr = itr.next 66 | 67 | itr.next = Node(data, None, itr) 68 | 69 | def insert_at(self, index, data): 70 | if index<0 or index>self.get_length(): 71 | raise Exception("Invalid Index") 72 | 73 | if index==0: 74 | self.insert_at_begining(data) 75 | return 76 | 77 | count = 0 78 | itr = self.head 79 | while itr: 80 | if count == index - 1: 81 | node = Node(data, itr.next, itr) 82 | if node.next: 83 | node.next.prev = node 84 | itr.next = node 85 | break 86 | 87 | itr = itr.next 88 | count += 1 89 | 90 | def remove_at(self, index): 91 | if index<0 or index>=self.get_length(): 92 | raise Exception("Invalid Index") 93 | 94 | if index==0: 95 | self.head = self.head.next 96 | self.head.prev = None 97 | return 98 | 99 | count = 0 100 | itr = self.head 101 | while itr: 102 | if count == index: 103 | itr.prev.next = itr.next 104 | if itr.next: 105 | itr.next.prev = itr.prev 106 | break 107 | 108 | itr = itr.next 109 | count+=1 110 | 111 | def insert_values(self, data_list): 112 | self.head = None 113 | for data in data_list: 114 | self.insert_at_end(data) 115 | 116 | 117 | if __name__ == '__main__': 118 | ll = DoublyLinkedList() 119 | ll.insert_values(["banana","mango","grapes","orange"]) 120 | ll.print_forward() 121 | ll.print_backward() 122 | ll.insert_at_end("figs") 123 | ll.print_forward() 124 | ll.insert_at(0,"jackfruit") 125 | ll.print_forward() 126 | ll.insert_at(6,"dates") 127 | ll.print_forward() 128 | ll.insert_at(2,"kiwi") 129 | ll.print_forward() 130 | 131 | 132 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/model/columns.json: -------------------------------------------------------------------------------- 1 | {"data_columns": ["total_sqft", "bath", "bhk", "1st block jayanagar", "1st phase jp nagar", "2nd phase judicial layout", "2nd stage nagarbhavi", "5th block hbr layout", "5th phase jp nagar", "6th phase jp nagar", "7th phase jp nagar", "8th phase jp nagar", "9th phase jp nagar", "aecs layout", "abbigere", "akshaya nagar", "ambalipura", "ambedkar nagar", "amruthahalli", "anandapura", "ananth nagar", "anekal", "anjanapura", "ardendale", "arekere", "attibele", "beml layout", "btm 2nd stage", "btm layout", "babusapalaya", "badavala nagar", "balagere", "banashankari", "banashankari stage ii", "banashankari stage iii", "banashankari stage v", "banashankari stage vi", "banaswadi", "banjara layout", "bannerghatta", "bannerghatta road", "basavangudi", "basaveshwara nagar", "battarahalli", "begur", "begur road", "bellandur", "benson town", "bharathi nagar", "bhoganhalli", "billekahalli", "binny pete", "bisuvanahalli", "bommanahalli", "bommasandra", "bommasandra industrial area", "bommenahalli", "brookefield", "budigere", "cv raman nagar", "chamrajpet", "chandapura", "channasandra", "chikka tirupathi", "chikkabanavar", "chikkalasandra", "choodasandra", "cooke town", "cox town", "cunningham road", "dasanapura", "dasarahalli", "devanahalli", "devarachikkanahalli", "dodda nekkundi", "doddaballapur", "doddakallasandra", "doddathoguru", "domlur", "dommasandra", "epip zone", "electronic city", "electronic city phase ii", "electronics city phase 1", "frazer town", "gm palaya", "garudachar palya", "giri nagar", "gollarapalya hosahalli", "gottigere", "green glen layout", "gubbalala", "gunjur", "hal 2nd stage", "hbr layout", "hrbr layout", "hsr layout", "haralur road", "harlur", "hebbal", "hebbal kempapura", "hegde nagar", "hennur", "hennur road", "hoodi", "horamavu agara", "horamavu banaswadi", "hormavu", "hosa road", "hosakerehalli", "hoskote", "hosur road", "hulimavu", "isro layout", "itpl", "iblur village", "indira nagar", "jp nagar", "jakkur", "jalahalli", "jalahalli east", "jigani", "judicial layout", "kr puram", "kadubeesanahalli", "kadugodi", "kaggadasapura", "kaggalipura", "kaikondrahalli", "kalena agrahara", "kalyan nagar", "kambipura", "kammanahalli", "kammasandra", "kanakapura", "kanakpura road", "kannamangala", "karuna nagar", "kasavanhalli", "kasturi nagar", "kathriguppe", "kaval byrasandra", "kenchenahalli", "kengeri", "kengeri satellite town", "kereguddadahalli", "kodichikkanahalli", "kodigehaali", "kodigehalli", "kodihalli", "kogilu", "konanakunte", "koramangala", "kothannur", "kothanur", "kudlu", "kudlu gate", "kumaraswami layout", "kundalahalli", "lb shastri nagar", "laggere", "lakshminarayana pura", "lingadheeranahalli", "magadi road", "mahadevpura", "mahalakshmi layout", "mallasandra", "malleshpalya", "malleshwaram", "marathahalli", "margondanahalli", "marsur", "mico layout", "munnekollal", "murugeshpalya", "mysore road", "ngr layout", "nri layout", "nagarbhavi", "nagasandra", "nagavara", "nagavarapalya", "narayanapura", "neeladri nagar", "nehru nagar", "ombr layout", "old airport road", "old madras road", "padmanabhanagar", "pai layout", "panathur", "parappana agrahara", "pattandur agrahara", "poorna pragna layout", "prithvi layout", "r.t. nagar", "rachenahalli", "raja rajeshwari nagar", "rajaji nagar", "rajiv nagar", "ramagondanahalli", "ramamurthy nagar", "rayasandra", "sahakara nagar", "sanjay nagar", "sarakki nagar", "sarjapur", "sarjapur road", "sarjapura - attibele road", "sector 2 hsr layout", "sector 7 hsr layout", "seegehalli", "shampura", "shivaji nagar", "singasandra", "somasundara palya", "sompura", "sonnenahalli", "subramanyapura", "sultan palaya", "tc palaya", "talaghattapura", "thanisandra", "thigalarapalya", "thubarahalli", "tindlu", "tumkur road", "ulsoor", "uttarahalli", "varthur", "varthur road", "vasanthapura", "vidyaranyapura", "vijayanagar", "vishveshwarya layout", "vishwapriya layout", "vittasandra", "whitefield", "yelachenahalli", "yelahanka", "yelahanka new town", "yelenahalli", "yeshwanthpur"]} -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/server/artifacts/columns.json: -------------------------------------------------------------------------------- 1 | {"data_columns": ["total_sqft", "bath", "bhk", "1st block jayanagar", "1st phase jp nagar", "2nd phase judicial layout", "2nd stage nagarbhavi", "5th block hbr layout", "5th phase jp nagar", "6th phase jp nagar", "7th phase jp nagar", "8th phase jp nagar", "9th phase jp nagar", "aecs layout", "abbigere", "akshaya nagar", "ambalipura", "ambedkar nagar", "amruthahalli", "anandapura", "ananth nagar", "anekal", "anjanapura", "ardendale", "arekere", "attibele", "beml layout", "btm 2nd stage", "btm layout", "babusapalaya", "badavala nagar", "balagere", "banashankari", "banashankari stage ii", "banashankari stage iii", "banashankari stage v", "banashankari stage vi", "banaswadi", "banjara layout", "bannerghatta", "bannerghatta road", "basavangudi", "basaveshwara nagar", "battarahalli", "begur", "begur road", "bellandur", "benson town", "bharathi nagar", "bhoganhalli", "billekahalli", "binny pete", "bisuvanahalli", "bommanahalli", "bommasandra", "bommasandra industrial area", "bommenahalli", "brookefield", "budigere", "cv raman nagar", "chamrajpet", "chandapura", "channasandra", "chikka tirupathi", "chikkabanavar", "chikkalasandra", "choodasandra", "cooke town", "cox town", "cunningham road", "dasanapura", "dasarahalli", "devanahalli", "devarachikkanahalli", "dodda nekkundi", "doddaballapur", "doddakallasandra", "doddathoguru", "domlur", "dommasandra", "epip zone", "electronic city", "electronic city phase ii", "electronics city phase 1", "frazer town", "gm palaya", "garudachar palya", "giri nagar", "gollarapalya hosahalli", "gottigere", "green glen layout", "gubbalala", "gunjur", "hal 2nd stage", "hbr layout", "hrbr layout", "hsr layout", "haralur road", "harlur", "hebbal", "hebbal kempapura", "hegde nagar", "hennur", "hennur road", "hoodi", "horamavu agara", "horamavu banaswadi", "hormavu", "hosa road", "hosakerehalli", "hoskote", "hosur road", "hulimavu", "isro layout", "itpl", "iblur village", "indira nagar", "jp nagar", "jakkur", "jalahalli", "jalahalli east", "jigani", "judicial layout", "kr puram", "kadubeesanahalli", "kadugodi", "kaggadasapura", "kaggalipura", "kaikondrahalli", "kalena agrahara", "kalyan nagar", "kambipura", "kammanahalli", "kammasandra", "kanakapura", "kanakpura road", "kannamangala", "karuna nagar", "kasavanhalli", "kasturi nagar", "kathriguppe", "kaval byrasandra", "kenchenahalli", "kengeri", "kengeri satellite town", "kereguddadahalli", "kodichikkanahalli", "kodigehaali", "kodigehalli", "kodihalli", "kogilu", "konanakunte", "koramangala", "kothannur", "kothanur", "kudlu", "kudlu gate", "kumaraswami layout", "kundalahalli", "lb shastri nagar", "laggere", "lakshminarayana pura", "lingadheeranahalli", "magadi road", "mahadevpura", "mahalakshmi layout", "mallasandra", "malleshpalya", "malleshwaram", "marathahalli", "margondanahalli", "marsur", "mico layout", "munnekollal", "murugeshpalya", "mysore road", "ngr layout", "nri layout", "nagarbhavi", "nagasandra", "nagavara", "nagavarapalya", "narayanapura", "neeladri nagar", "nehru nagar", "ombr layout", "old airport road", "old madras road", "padmanabhanagar", "pai layout", "panathur", "parappana agrahara", "pattandur agrahara", "poorna pragna layout", "prithvi layout", "r.t. nagar", "rachenahalli", "raja rajeshwari nagar", "rajaji nagar", "rajiv nagar", "ramagondanahalli", "ramamurthy nagar", "rayasandra", "sahakara nagar", "sanjay nagar", "sarakki nagar", "sarjapur", "sarjapur road", "sarjapura - attibele road", "sector 2 hsr layout", "sector 7 hsr layout", "seegehalli", "shampura", "shivaji nagar", "singasandra", "somasundara palya", "sompura", "sonnenahalli", "subramanyapura", "sultan palaya", "tc palaya", "talaghattapura", "thanisandra", "thigalarapalya", "thubarahalli", "tindlu", "tumkur road", "ulsoor", "uttarahalli", "varthur", "varthur road", "vasanthapura", "vidyaranyapura", "vijayanagar", "vishveshwarya layout", "vishwapriya layout", "vittasandra", "whitefield", "yelachenahalli", "yelahanka", "yelahanka new town", "yelenahalli", "yeshwanthpur"]} -------------------------------------------------------------------------------- /DataStructures/3_LinkedList/Solution/singly_linked_list_exercise.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self, data=None, next=None): 3 | self.data = data 4 | self.next = next 5 | 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | 10 | def print(self): 11 | if self.head is None: 12 | print("Linked list is empty") 13 | return 14 | 15 | itr = self.head 16 | llstr = '' 17 | while itr: 18 | llstr += str(itr.data) + ' --> ' 19 | itr = itr.next 20 | print(llstr) 21 | 22 | def get_length(self): 23 | count = 0 24 | itr = self.head 25 | while itr: 26 | count+=1 27 | itr = itr.next 28 | 29 | return count 30 | 31 | def insert_at_begining(self, data): 32 | node = Node(data, self.head) 33 | self.head = node 34 | 35 | def insert_at_end(self, data): 36 | if self.head is None: 37 | self.head = Node(data, None) 38 | return 39 | 40 | itr = self.head 41 | 42 | while itr.next: 43 | itr = itr.next 44 | 45 | itr.next = Node(data, None) 46 | 47 | def insert_at(self, index, data): 48 | if index<0 or index>self.get_length(): 49 | raise Exception("Invalid Index") 50 | 51 | if index==0: 52 | self.insert_at_begining(data) 53 | return 54 | 55 | count = 0 56 | itr = self.head 57 | while itr: 58 | if count == index - 1: 59 | node = Node(data, itr.next) 60 | itr.next = node 61 | break 62 | 63 | itr = itr.next 64 | count += 1 65 | 66 | def remove_at(self, index): 67 | if index<0 or index>=self.get_length(): 68 | raise Exception("Invalid Index") 69 | 70 | if index==0: 71 | self.head = self.head.next 72 | return 73 | 74 | count = 0 75 | itr = self.head 76 | while itr: 77 | if count == index - 1: 78 | itr.next = itr.next.next 79 | break 80 | 81 | itr = itr.next 82 | count+=1 83 | 84 | def insert_values(self, data_list): 85 | self.head = None 86 | for data in data_list: 87 | self.insert_at_end(data) 88 | 89 | 90 | def insert_after_value(self, data_after, data_to_insert): 91 | if self.head is None: 92 | return 93 | 94 | if self.head.data==data_after: 95 | self.head.next = Node(data_to_insert,self.head.next) 96 | return 97 | 98 | itr = self.head 99 | while itr: 100 | if itr.data == data_after: 101 | itr.next = Node(data_to_insert, itr.next) 102 | break 103 | 104 | itr = itr.next 105 | 106 | def remove_by_value(self, data): 107 | if self.head is None: 108 | return 109 | 110 | if self.head.data == data: 111 | self.head = self.head.next 112 | return 113 | 114 | itr = self.head 115 | while itr.next: 116 | if itr.next.data == data: 117 | itr.next = itr.next.next 118 | break 119 | itr = itr.next 120 | 121 | if __name__ == '__main__': 122 | ll = LinkedList() 123 | ll.insert_values(["banana","mango","grapes","orange"]) 124 | ll.print() 125 | ll.insert_after_value("mango","apple") 126 | ll.print() 127 | ll.remove_by_value("orange") 128 | ll.print() 129 | ll.remove_by_value("figs") 130 | ll.print() 131 | ll.remove_by_value("banana") 132 | ll.remove_by_value("mango") 133 | ll.remove_by_value("apple") 134 | ll.remove_by_value("grapes") 135 | ll.print() 136 | 137 | # ll.insert_values([45,7,12,567,99]) 138 | # ll.insert_at_end(67) 139 | # ll.print() 140 | 141 | -------------------------------------------------------------------------------- /DataScience/BangloreHomePrices/readme.md: -------------------------------------------------------------------------------- 1 | ![](BHP_website.PNG) 2 | 3 | This data science project series walks through step by step process of how to build a real estate price prediction website. We will first build a model using sklearn and linear regression using banglore home prices dataset from kaggle.com. Second step would be to write a python flask server that uses the saved model to serve http requests. Third component is the website built in html, css and javascript that allows user to enter home square ft area, bedrooms etc and it will call python flask server to retrieve the predicted price. During model building we will cover almost all data science concepts such as data load and cleaning, outlier detection and removal, feature engineering, dimensionality reduction, gridsearchcv for hyperparameter tunning, k fold cross validation etc. Technology and tools wise this project covers, 4 | 5 | 1. Python 6 | 2. Numpy and Pandas for data cleaning 7 | 3. Matplotlib for data visualization 8 | 4. Sklearn for model building 9 | 5. Jupyter notebook, visual studio code and pycharm as IDE 10 | 6. Python flask for http server 11 | 7. HTML/CSS/Javascript for UI 12 | 13 | # Deploy this app to cloud (AWS EC2) 14 | 15 | 1. Create EC2 instance using amazon console, also in security group add a rule to allow HTTP incoming traffic 16 | 2. Now connect to your instance using a command like this, 17 | ``` 18 | ssh -i "C:\Users\Viral\.ssh\Banglore.pem" ubuntu@ec2-3-133-88-210.us-east-2.compute.amazonaws.com 19 | ``` 20 | 3. nginx setup 21 | 1. Install nginx on EC2 instance using these commands, 22 | ``` 23 | sudo apt-get update 24 | sudo apt-get install nginx 25 | ``` 26 | 2. Above will install nginx as well as run it. Check status of nginx using 27 | ``` 28 | sudo service nginx status 29 | ``` 30 | 3. Here are the commands to start/stop/restart nginx 31 | ``` 32 | sudo service nginx start 33 | sudo service nginx stop 34 | sudo service nginx restart 35 | ``` 36 | 4. Now when you load cloud url in browser you will see a message saying "welcome to nginx" This means your nginx is setup and running. 37 | 4. Now you need to copy all your code to EC2 instance. You can do this either using git or copy files using winscp. We will use winscp. You can download winscp from here: https://winscp.net/eng/download.php 38 | 5. Once you connect to EC2 instance from winscp (instruction in a youtube video), you can now copy all code files into /home/ubuntu/ folder. The full path of your root folder is now: **/home/ubuntu/BangloreHomePrices** 39 | 6. After copying code on EC2 server now we can point nginx to load our property website by default. For below steps, 40 | 1. Create this file /etc/nginx/sites-available/bhp.conf. The file content looks like this, 41 | ``` 42 | server { 43 | listen 80; 44 | server_name bhp; 45 | root /home/ubuntu/BangloreHomePrices/client; 46 | index app.html; 47 | location /api/ { 48 | rewrite ^/api(.*) $1 break; 49 | proxy_pass http://127.0.0.1:5000; 50 | } 51 | } 52 | ``` 53 | 2. Create symlink for this file in /etc/nginx/sites-enabled by running this command, 54 | ``` 55 | sudo ln -v -s /etc/nginx/sites-available/bhp.conf 56 | ``` 57 | 3. Remove symlink for default file in /etc/nginx/sites-enabled directory, 58 | ``` 59 | sudo unlink default 60 | ``` 61 | 4. Restart nginx, 62 | ``` 63 | sudo service nginx restart 64 | ``` 65 | 7. Now install python packages and start flask server 66 | ``` 67 | sudo apt-get install python3-pip 68 | sudo pip3 install -r /home/ubuntu/BangloreHomePrices/server/requirements.txt 69 | python3 /home/ubuntu/BangloreHomePrices/client/server.py 70 | ``` 71 | Running last command above will prompt that server is running on port 5000. 72 | 8. Now just load your cloud url in browser (for me it was http://ec2-3-133-88-210.us-east-2.compute.amazonaws.com/) and this will be fully functional website running in production cloud environment 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ML/12_KFold_Cross_Validation/Exercise/exercise_kfold_validation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "from sklearn.datasets import load_iris\n", 12 | "from sklearn.model_selection import cross_val_score\n", 13 | "from sklearn.linear_model import LogisticRegression\n", 14 | "from sklearn.tree import DecisionTreeClassifier\n", 15 | "from sklearn.svm import SVC\n", 16 | "from sklearn.ensemble import RandomForestClassifier\n", 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 2, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "iris = load_iris()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "**Logistic Regression**" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 3, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "array([ 0.96078431, 0.92156863, 0.95833333])" 47 | ] 48 | }, 49 | "execution_count": 3, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "l_scores = cross_val_score(LogisticRegression(), iris.data, iris.target)\n", 56 | "l_scores" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "0.94689542483660138" 68 | ] 69 | }, 70 | "execution_count": 4, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "np.average(l_scores)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "**Decision Tree**" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 5, 89 | "metadata": { 90 | "scrolled": true 91 | }, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "array([ 0.98039216, 0.92156863, 0.97916667])" 97 | ] 98 | }, 99 | "execution_count": 5, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "d_scores = cross_val_score(DecisionTreeClassifier(), iris.data, iris.target)\n", 106 | "d_scores" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "data": { 116 | "text/plain": [ 117 | "0.96037581699346397" 118 | ] 119 | }, 120 | "execution_count": 6, 121 | "metadata": {}, 122 | "output_type": "execute_result" 123 | } 124 | ], 125 | "source": [ 126 | "np.average(d_scores)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "**Support Vector Machine (SVM)**" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 7, 139 | "metadata": { 140 | "scrolled": true 141 | }, 142 | "outputs": [ 143 | { 144 | "data": { 145 | "text/plain": [ 146 | "array([ 0.98039216, 0.96078431, 0.97916667])" 147 | ] 148 | }, 149 | "execution_count": 7, 150 | "metadata": {}, 151 | "output_type": "execute_result" 152 | } 153 | ], 154 | "source": [ 155 | "s_scores = cross_val_score(SVC(), iris.data, iris.target)\n", 156 | "s_scores" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 8, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "0.97344771241830064" 168 | ] 169 | }, 170 | "execution_count": 8, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "np.average(s_scores)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": {}, 182 | "source": [ 183 | "**Random Forest**" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 11, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "data": { 193 | "text/plain": [ 194 | "array([ 0.98039216, 0.92156863, 0.97916667])" 195 | ] 196 | }, 197 | "execution_count": 11, 198 | "metadata": {}, 199 | "output_type": "execute_result" 200 | } 201 | ], 202 | "source": [ 203 | "r_scores = cross_val_score(RandomForestClassifier(n_estimators=40), iris.data, iris.target)\n", 204 | "r_scores" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 12, 210 | "metadata": { 211 | "scrolled": false 212 | }, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "0.96037581699346397" 218 | ] 219 | }, 220 | "execution_count": 12, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "np.average(r_scores)" 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "metadata": {}, 232 | "source": [ 233 | "**Best score so far is from SVM: 0.97344771241830064**" 234 | ] 235 | } 236 | ], 237 | "metadata": { 238 | "kernelspec": { 239 | "display_name": "Python 3", 240 | "language": "python", 241 | "name": "python3" 242 | }, 243 | "language_info": { 244 | "codemirror_mode": { 245 | "name": "ipython", 246 | "version": 3 247 | }, 248 | "file_extension": ".py", 249 | "mimetype": "text/x-python", 250 | "name": "python", 251 | "nbconvert_exporter": "python", 252 | "pygments_lexer": "ipython3", 253 | "version": "3.6.1" 254 | } 255 | }, 256 | "nbformat": 4, 257 | "nbformat_minor": 2 258 | } 259 | -------------------------------------------------------------------------------- /matpltlib/10_subplots.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "

Matplotlib Tutorial: Subplots

" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "%matplotlib inline\n", 19 | "import matplotlib.pyplot as plt" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 35, 25 | "metadata": { 26 | "scrolled": true 27 | }, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/plain": [ 32 | "" 33 | ] 34 | }, 35 | "execution_count": 35, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | }, 39 | { 40 | "data": { 41 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAACFCAYAAACwoTTBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAC4FJREFUeJzt3X+sXGWdx/H317aoK0rBXpW0xYux\n0cWNCnZrXTaG2A0WMC2JkNTsat1gGiMkmF3jlt1Eoy5Z3T+UuLpuWIqpP3ZB6w8qStguP/7YZKm0\n/KiLFbkqLg1I0QJVN4tWv/5xngtjn7l3Zpi5c6bh/Upu7jnPeeY533k6937uOXPmNDITSZI6Pavt\nAiRJk8dwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUmVx2wXMZ9myZTk9Pd12GZJ0\nTNm7d+9PM3NqmDEmOhymp6fZs2dP22VI0jElIn487BieVpIkVQwHSVLFcJAkVSb6PQfpWDa99Ztt\nl9Cq+z96XtslaAgeOUiSKoaDJKliOEiSKoaDJKliOEiSKoaDJKliOEiSKoaDJKliOEiSKoaDJKli\nOEiSKt5bSdJE8t5U7d6byiMHSVLFIwfNyb/cvKuonrk8cpAkVQwHSVLFcJAkVQwHSVKl73CIiEUR\ncWdEXF/WT42I3RFxX0RcGxHHlfZnl/WZsn26Y4zLSvu9EfHmUT8ZSdJoDHLkcCmwv2P9Y8AnMnMV\n8ChwUWm/CHg0M18OfKL0IyJOAzYBrwLWA/8cEYuGK1+StBD6CoeIWAGcB1xV1gN4E7CjdNkOnF+W\nN5Z1yvZ1pf9G4JrMfCIzfwTMAGtG8SQkSaPV75HDFcD7gd+W9RcCj2XmkbJ+AFhelpcDDwCU7Y+X\n/k+2d3mMJGmC9PwQXES8BTiYmXsj4qzZ5i5ds8e2+R7Tub8twBaAU045pVd58/JDXH6IS9LT08+R\nw5nAhoi4H7iG5nTSFcDSiJgNlxXAg2X5ALASoGw/ATjU2d7lMU/KzCszc3Vmrp6amhr4CUmShtcz\nHDLzssxckZnTNG8o35yZfw7cAlxQum0GrivLO8s6ZfvNmZmlfVO5mulUYBXw7ZE9E0nSyAxzb6W/\nAa6JiL8H7gS2lfZtwOcjYobmiGETQGbeExFfAr4LHAEuzszfDLF/SdICGSgcMvNW4Nay/EO6XG2U\nmf8PXDjH4y8HLh+0SEnSePkJaUlSxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lS\nxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSxXCQ\nJFUMB0lSxXCQJFUMB0lSxXCQJFUMB0lSpWc4RMTKiLglIvZHxD0RcWlpPykidkXEfeX7iaU9IuKT\nETETEfsi4oyOsTaX/vdFxOaFe1qSpGH0c+RwBPjrzPxDYC1wcUScBmwFbsrMVcBNZR3gHGBV+doC\nfAaaMAE+CLweWAN8cDZQJEmTpWc4ZOZDmXlHWf45sB9YDmwEtpdu24Hzy/JG4HPZuA1YGhEnA28G\ndmXmocx8FNgFrB/ps5EkjcRA7zlExDRwOrAbeHFmPgRNgAAvKt2WAw90POxAaZur/eh9bImIPRGx\n55FHHhmkPEnSiPQdDhFxPPAV4L2ZeXi+rl3acp7232/IvDIzV2fm6qmpqX7LkySNUF/hEBFLaILh\ni5n51dL8cDldRPl+sLQfAFZ2PHwF8OA87ZKkCdPP1UoBbAP2Z+bHOzbtBGavONoMXNfR/o5y1dJa\n4PFy2ulG4OyIOLG8EX12aZMkTZjFffQ5E3g78J2IuKu0/S3wUeBLEXER8L/AhWXbt4BzgRng/4C/\nBMjMQxHxEeD20u/DmXloJM9CkjRSPcMhM/+L7u8XAKzr0j+Bi+cY62rg6kEKlCSNn5+QliRVDAdJ\nUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVw\nkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRVDAdJUsVwkCRV\nxh4OEbE+Iu6NiJmI2Dru/UuSehtrOETEIuDTwDnAacDbIuK0cdYgSept3EcOa4CZzPxhZv4KuAbY\nOOYaJEk9RGaOb2cRFwDrM/NdZf3twOsz85KOPluALWX1FcC98wy5DPjpApU7CtY3HOsbjvUN51iu\n76WZOTXM4IuHefDTEF3afi+dMvNK4Mq+BovYk5mrR1HYQrC+4VjfcKxvOM/0+sZ9WukAsLJjfQXw\n4JhrkCT1MO5wuB1YFRGnRsRxwCZg55hrkCT1MNbTSpl5JCIuAW4EFgFXZ+Y9QwzZ1+mnFlnfcKxv\nONY3nGd0fWN9Q1qSdGzwE9KSpIrhIEmqZWYrXzRXLd0C7AfuAS4t7ScBu4D7yvcTS/srgf8GngDe\n1zHOc4BvA3eXcT40x/7eCTwC3FW+3jWO+jrGWwTcCVw/x/6eDVwLzAC7gekJq6+1+QPuB75T9rtn\njv0F8Mkyf/uAMyasvrOAxzvm7wNjrG8psAP4XhnvDRM2f/3U18r80XzW6q6Or8PAeydl/gaob6D5\ny8xWw+Hk2QkEng98n+aWGv8IbC3tW4GPleUXAX8MXH7U5ARwfFleQvOLdW2X/b0T+NS46+sY76+A\nf2PuX77vAf6lLG8Crp2w+lqbP5pfvst67O9c4IbyelgL7J6w+s6aa27HUN92SpgDxwFLJ2z++qmv\ntfnrGHMR8BOaD5hNzPz1Wd9A85eZ7Z1WysyHMvOOsvxzmgRdTnM7je2l23bg/NLnYGbeDvz6qHEy\nM39RVpeUr6HfZR9VfQARsQI4D7hqnl12jrsDWBcR3T402FZ9AxllfX3aCHyuvB5uA5ZGxMkTVN9A\nRlVfRLwAeCOwrfT7VWY+1mWXrczfAPUNZIH+fdcBP8jMH3fZNgmvv/nqG9hEvOcQEdPA6TR/9b84\nMx+CZgJpErPX4xdFxF3AQWBXZu6eo+tbI2JfROyIiJVz9Bl5fcAVwPuB387TZznwQBn3CM0h4Asn\nqD5ob/4S+I+I2Ftur9LNk/NXHChtk1IfwBsi4u6IuCEiXtVPbSOo72U0pwM/GxF3RsRVEfG8Lv3a\nmr9+64N25q/TJuDf59jW5uuvn/pgwPlrPRwi4njgKzTnyQ4/nTEy8zeZ+VqaT1yviYg/6tLtGzTn\n8V8N/CdPpfOC1hcRbwEOZubeXl27tPU8Ahpjfa3MX3FmZp5BczffiyPijd121aVtwedvgPruoDnc\nfw3wT8DX+xl4BPUtBs4APpOZpwO/pDldUe2qS9s45q/f+tqav9lxjgM2AF+eq0uXtnG9/vqpb+D5\nazUcImIJzcR8MTO/Wpofnj0cK98P9jteORy9FVjfZdvPMvOJsvqvwOvGVN+ZwIaIuJ/mLrRviogv\ndOn35K1FImIxcAJwaFLqa3H+yMwHy/eDwNdo7u57tIFvzTLO+jLz8Ozpz8z8FrAkIpaNob4DwIGO\no+kdNL+Mu/VrY/76qq/F+Zt1DnBHZj48z/No5fXXT31PZ/5aC4dyPn0bsD8zP96xaSewuSxvBq7r\nMc5URCwty88F/ozmqoej+3We/9tAc45vwevLzMsyc0VmTtMc9t2cmX/RpWvnuBeUfnP+5THu+tqa\nv4h4XkQ8f3YZOBv4ny5ddwLviMZa4PHZw/NJqC8iXjL7HlJErKH52fvZQteXmT8BHoiIV5SmdcB3\nu3RtZf76ra+t+evwNuY/ZdPK/PVb36DzB7R6tdKf0hx27eOpy6vOpTnPfhPNpVw3ASeV/i+hSefD\nwGNl+QXAq2kuwdxH80P5gY59fBjYUJb/geaSsbtpLiF75TjqO2rMs+i4YuCo+p5Dc0g4Q3Np7ssm\nrL5W5o/mnPTdPHWp8t917OPdwLvLctD8R1I/oLmsdPWE1XdJx/zdBvzJuP59gdcCe8pYX+epyyNb\nn78B6mtz/v6A5hfpCUftY1Lmr5/6Bpq/zPT2GZKkWutvSEuSJo/hIEmqGA6SpIrhIEmqGA6SpIrh\nIEmqGA6SpMrvACIkdR2GuvabAAAAAElFTkSuQmCC\n", 42 | "text/plain": [ 43 | "" 44 | ] 45 | }, 46 | "metadata": {}, 47 | "output_type": "display_data" 48 | } 49 | ], 50 | "source": [ 51 | "year=[2014,2015,2016,2017]\n", 52 | "income=[4000,4500,5300,4600]\n", 53 | "expense=[2800,3000,2800,3400]\n", 54 | "\n", 55 | "plt.subplot(2,1,1)\n", 56 | "# income.set_title('Income')\n", 57 | "plt.bar(year,income)\n", 58 | "\n", 59 | "\n", 60 | "# plt.subplot(2,1,2)\n", 61 | "# plt.bar(year,expense,color='green')" 62 | ] 63 | } 64 | ], 65 | "metadata": { 66 | "kernelspec": { 67 | "display_name": "Python 3", 68 | "language": "python", 69 | "name": "python3" 70 | }, 71 | "language_info": { 72 | "codemirror_mode": { 73 | "name": "ipython", 74 | "version": 3 75 | }, 76 | "file_extension": ".py", 77 | "mimetype": "text/x-python", 78 | "name": "python", 79 | "nbconvert_exporter": "python", 80 | "pygments_lexer": "ipython3", 81 | "version": "3.6.3" 82 | } 83 | }, 84 | "nbformat": 4, 85 | "nbformat_minor": 2 86 | } 87 | -------------------------------------------------------------------------------- /DataStructures/4_HashTable_2_Collisions/Solution/exercise_poem_find_word_occurances.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Two roads diverged in a yellow wood,\n", 13 | "\n", 14 | "And sorry I could not travel both\n", 15 | "\n", 16 | "And be one traveler, long I stood\n", 17 | "\n", 18 | "And looked down one as far as I could\n", 19 | "\n", 20 | "To where it bent in the undergrowth;\n", 21 | "\n", 22 | "\n", 23 | "\n", 24 | "Then took the other, as just as fair,\n", 25 | "\n", 26 | "And having perhaps the better claim,\n", 27 | "\n", 28 | "Because it was grassy and wanted wear;\n", 29 | "\n", 30 | "Though as for that the passing there\n", 31 | "\n", 32 | "Had worn them really about the same,\n", 33 | "\n", 34 | "\n", 35 | "\n", 36 | "And both that morning equally lay\n", 37 | "\n", 38 | "In leaves no step had trodden black.\n", 39 | "\n", 40 | "Oh, I kept the first for another day!\n", 41 | "\n", 42 | "Yet knowing how way leads on to way,\n", 43 | "\n", 44 | "I doubted if I should ever come back.\n", 45 | "\n", 46 | "\n", 47 | "\n", 48 | "I shall be telling this with a sigh\n", 49 | "\n", 50 | "Somewhere ages and ages hence:\n", 51 | "\n", 52 | "Two roads diverged in a wood, and I—\n", 53 | "\n", 54 | "I took the one less traveled by,\n", 55 | "\n", 56 | "And that has made all the difference.\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "with open(\"poem.txt\",\"r\") as f:\n", 62 | " for line in f:\n", 63 | " print(line)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "word_count = {}\n", 73 | "with open(\"poem.txt\",\"r\") as f:\n", 74 | " for line in f:\n", 75 | " tokens = line.split(' ')\n", 76 | " for token in tokens:\n", 77 | " token=token.replace('\\n','')\n", 78 | " if token in word_count:\n", 79 | " word_count[token]+=1\n", 80 | " else:\n", 81 | " word_count[token]=1" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "{'Two': 2,\n", 93 | " 'roads': 2,\n", 94 | " 'diverged': 2,\n", 95 | " 'in': 3,\n", 96 | " 'a': 3,\n", 97 | " 'yellow': 1,\n", 98 | " 'wood,': 2,\n", 99 | " 'And': 6,\n", 100 | " 'sorry': 1,\n", 101 | " 'I': 8,\n", 102 | " 'could': 2,\n", 103 | " 'not': 1,\n", 104 | " 'travel': 1,\n", 105 | " 'both': 2,\n", 106 | " 'be': 2,\n", 107 | " 'one': 3,\n", 108 | " 'traveler,': 1,\n", 109 | " 'long': 1,\n", 110 | " 'stood': 1,\n", 111 | " 'looked': 1,\n", 112 | " 'down': 1,\n", 113 | " 'as': 5,\n", 114 | " 'far': 1,\n", 115 | " 'To': 1,\n", 116 | " 'where': 1,\n", 117 | " 'it': 2,\n", 118 | " 'bent': 1,\n", 119 | " 'the': 8,\n", 120 | " 'undergrowth;': 1,\n", 121 | " '': 3,\n", 122 | " 'Then': 1,\n", 123 | " 'took': 2,\n", 124 | " 'other,': 1,\n", 125 | " 'just': 1,\n", 126 | " 'fair,': 1,\n", 127 | " 'having': 1,\n", 128 | " 'perhaps': 1,\n", 129 | " 'better': 1,\n", 130 | " 'claim,': 1,\n", 131 | " 'Because': 1,\n", 132 | " 'was': 1,\n", 133 | " 'grassy': 1,\n", 134 | " 'and': 3,\n", 135 | " 'wanted': 1,\n", 136 | " 'wear;': 1,\n", 137 | " 'Though': 1,\n", 138 | " 'for': 2,\n", 139 | " 'that': 3,\n", 140 | " 'passing': 1,\n", 141 | " 'there': 1,\n", 142 | " 'Had': 1,\n", 143 | " 'worn': 1,\n", 144 | " 'them': 1,\n", 145 | " 'really': 1,\n", 146 | " 'about': 1,\n", 147 | " 'same,': 1,\n", 148 | " 'morning': 1,\n", 149 | " 'equally': 1,\n", 150 | " 'lay': 1,\n", 151 | " 'In': 1,\n", 152 | " 'leaves': 1,\n", 153 | " 'no': 1,\n", 154 | " 'step': 1,\n", 155 | " 'had': 1,\n", 156 | " 'trodden': 1,\n", 157 | " 'black.': 1,\n", 158 | " 'Oh,': 1,\n", 159 | " 'kept': 1,\n", 160 | " 'first': 1,\n", 161 | " 'another': 1,\n", 162 | " 'day!': 1,\n", 163 | " 'Yet': 1,\n", 164 | " 'knowing': 1,\n", 165 | " 'how': 1,\n", 166 | " 'way': 1,\n", 167 | " 'leads': 1,\n", 168 | " 'on': 1,\n", 169 | " 'to': 1,\n", 170 | " 'way,': 1,\n", 171 | " 'doubted': 1,\n", 172 | " 'if': 1,\n", 173 | " 'should': 1,\n", 174 | " 'ever': 1,\n", 175 | " 'come': 1,\n", 176 | " 'back.': 1,\n", 177 | " 'shall': 1,\n", 178 | " 'telling': 1,\n", 179 | " 'this': 1,\n", 180 | " 'with': 1,\n", 181 | " 'sigh': 1,\n", 182 | " 'Somewhere': 1,\n", 183 | " 'ages': 2,\n", 184 | " 'hence:': 1,\n", 185 | " 'I—': 1,\n", 186 | " 'less': 1,\n", 187 | " 'traveled': 1,\n", 188 | " 'by,': 1,\n", 189 | " 'has': 1,\n", 190 | " 'made': 1,\n", 191 | " 'all': 1,\n", 192 | " 'difference.': 1}" 193 | ] 194 | }, 195 | "execution_count": 5, 196 | "metadata": {}, 197 | "output_type": "execute_result" 198 | } 199 | ], 200 | "source": [ 201 | "word_count" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "kernelspec": { 207 | "display_name": "Python 3", 208 | "language": "python", 209 | "name": "python3" 210 | }, 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | "version": "3.7.3" 222 | } 223 | }, 224 | "nbformat": 4, 225 | "nbformat_minor": 2 226 | } 227 | -------------------------------------------------------------------------------- /Basics/Hindi/9_modules/9_modules.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "**We use gadgets like computer, car, cell phone in our day to day life. Now they are invented by other people but we make use of it. This whole idea of \"reuse\" applies to programming as well**" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "**In python modules provide a way to reuse code written by other people**" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import math" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": { 30 | "scrolled": true 31 | }, 32 | "outputs": [ 33 | { 34 | "data": { 35 | "text/plain": [ 36 | "4.0" 37 | ] 38 | }, 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "output_type": "execute_result" 42 | } 43 | ], 44 | "source": [ 45 | "math.sqrt(16)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 3, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "['__doc__',\n", 57 | " '__loader__',\n", 58 | " '__name__',\n", 59 | " '__package__',\n", 60 | " '__spec__',\n", 61 | " 'acos',\n", 62 | " 'acosh',\n", 63 | " 'asin',\n", 64 | " 'asinh',\n", 65 | " 'atan',\n", 66 | " 'atan2',\n", 67 | " 'atanh',\n", 68 | " 'ceil',\n", 69 | " 'copysign',\n", 70 | " 'cos',\n", 71 | " 'cosh',\n", 72 | " 'degrees',\n", 73 | " 'e',\n", 74 | " 'erf',\n", 75 | " 'erfc',\n", 76 | " 'exp',\n", 77 | " 'expm1',\n", 78 | " 'fabs',\n", 79 | " 'factorial',\n", 80 | " 'floor',\n", 81 | " 'fmod',\n", 82 | " 'frexp',\n", 83 | " 'fsum',\n", 84 | " 'gamma',\n", 85 | " 'gcd',\n", 86 | " 'hypot',\n", 87 | " 'inf',\n", 88 | " 'isclose',\n", 89 | " 'isfinite',\n", 90 | " 'isinf',\n", 91 | " 'isnan',\n", 92 | " 'ldexp',\n", 93 | " 'lgamma',\n", 94 | " 'log',\n", 95 | " 'log10',\n", 96 | " 'log1p',\n", 97 | " 'log2',\n", 98 | " 'modf',\n", 99 | " 'nan',\n", 100 | " 'pi',\n", 101 | " 'pow',\n", 102 | " 'radians',\n", 103 | " 'remainder',\n", 104 | " 'sin',\n", 105 | " 'sinh',\n", 106 | " 'sqrt',\n", 107 | " 'tan',\n", 108 | " 'tanh',\n", 109 | " 'tau',\n", 110 | " 'trunc']" 111 | ] 112 | }, 113 | "execution_count": 3, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "dir(math)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "**or google \"Python 3 math module\"**" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 4, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "3.141592653589793" 138 | ] 139 | }, 140 | "execution_count": 4, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "math.pi" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 5, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/plain": [ 157 | "2.0" 158 | ] 159 | }, 160 | "execution_count": 5, 161 | "metadata": {}, 162 | "output_type": "execute_result" 163 | } 164 | ], 165 | "source": [ 166 | "math.log10(100)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 6, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "data": { 176 | "text/plain": [ 177 | "3.0" 178 | ] 179 | }, 180 | "execution_count": 6, 181 | "metadata": {}, 182 | "output_type": "execute_result" 183 | } 184 | ], 185 | "source": [ 186 | "math.log10(1000)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 7, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "import calendar" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 11, 201 | "metadata": { 202 | "scrolled": true 203 | }, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | " January 2020\n", 210 | "Mo Tu We Th Fr Sa Su\n", 211 | " 1 2 3 4 5\n", 212 | " 6 7 8 9 10 11 12\n", 213 | "13 14 15 16 17 18 19\n", 214 | "20 21 22 23 24 25 26\n", 215 | "27 28 29 30 31\n", 216 | "\n" 217 | ] 218 | } 219 | ], 220 | "source": [ 221 | "jan = calendar.month(2020,1)\n", 222 | "print(jan)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 12, 228 | "metadata": { 229 | "scrolled": false 230 | }, 231 | "outputs": [ 232 | { 233 | "data": { 234 | "text/plain": [ 235 | "True" 236 | ] 237 | }, 238 | "execution_count": 12, 239 | "metadata": {}, 240 | "output_type": "execute_result" 241 | } 242 | ], 243 | "source": [ 244 | "calendar.isleap(2020)" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 13, 250 | "metadata": {}, 251 | "outputs": [ 252 | { 253 | "data": { 254 | "text/plain": [ 255 | "False" 256 | ] 257 | }, 258 | "execution_count": 13, 259 | "metadata": {}, 260 | "output_type": "execute_result" 261 | } 262 | ], 263 | "source": [ 264 | "calendar.isleap(2019)" 265 | ] 266 | }, 267 | { 268 | "cell_type": "markdown", 269 | "metadata": {}, 270 | "source": [ 271 | "**Python 3 modules list**" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": {}, 277 | "source": [ 278 | "https://docs.python.org/3/py-modindex.html These come with standard python installation" 279 | ] 280 | } 281 | ], 282 | "metadata": { 283 | "kernelspec": { 284 | "display_name": "Python 3", 285 | "language": "python", 286 | "name": "python3" 287 | }, 288 | "language_info": { 289 | "codemirror_mode": { 290 | "name": "ipython", 291 | "version": 3 292 | }, 293 | "file_extension": ".py", 294 | "mimetype": "text/x-python", 295 | "name": "python", 296 | "nbconvert_exporter": "python", 297 | "pygments_lexer": "ipython3", 298 | "version": "3.7.3" 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 2 303 | } 304 | -------------------------------------------------------------------------------- /ML/15_gridsearch/Exercise/15_grid_search_cv_exercise.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "

Finding best model and hyper parameters for sklearn digits dataset classification" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from sklearn import datasets\n", 17 | "digits = datasets.load_digits()" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 2, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "from sklearn import svm\n", 27 | "from sklearn.ensemble import RandomForestClassifier\n", 28 | "from sklearn.linear_model import LogisticRegression\n", 29 | "from sklearn.naive_bayes import GaussianNB\n", 30 | "from sklearn.naive_bayes import MultinomialNB\n", 31 | "from sklearn.tree import DecisionTreeClassifier" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 3, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "model_params = {\n", 41 | " 'svm': {\n", 42 | " 'model': svm.SVC(gamma='auto'),\n", 43 | " 'params' : {\n", 44 | " 'C': [1,10,20],\n", 45 | " 'kernel': ['rbf','linear']\n", 46 | " } \n", 47 | " },\n", 48 | " 'random_forest': {\n", 49 | " 'model': RandomForestClassifier(),\n", 50 | " 'params' : {\n", 51 | " 'n_estimators': [1,5,10]\n", 52 | " }\n", 53 | " },\n", 54 | " 'logistic_regression' : {\n", 55 | " 'model': LogisticRegression(solver='liblinear',multi_class='auto'),\n", 56 | " 'params': {\n", 57 | " 'C': [1,5,10]\n", 58 | " }\n", 59 | " },\n", 60 | " 'naive_bayes_gaussian': {\n", 61 | " 'model': GaussianNB(),\n", 62 | " 'params': {}\n", 63 | " },\n", 64 | " 'naive_bayes_multinomial': {\n", 65 | " 'model': MultinomialNB(),\n", 66 | " 'params': {}\n", 67 | " },\n", 68 | " 'decision_tree': {\n", 69 | " 'model': DecisionTreeClassifier(),\n", 70 | " 'params': {\n", 71 | " 'criterion': ['gini','entropy'],\n", 72 | " \n", 73 | " }\n", 74 | " } \n", 75 | "}" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 4, 81 | "metadata": { 82 | "scrolled": true 83 | }, 84 | "outputs": [ 85 | { 86 | "name": "stderr", 87 | "output_type": "stream", 88 | "text": [ 89 | "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\model_selection\\_search.py:841: DeprecationWarning: The default of the `iid` parameter will change from True to False in version 0.22 and will be removed in 0.24. This will change numeric results when test-set sizes are unequal.\n", 90 | " DeprecationWarning)\n" 91 | ] 92 | }, 93 | { 94 | "data": { 95 | "text/html": [ 96 | "
\n", 97 | "\n", 110 | "\n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | "
modelbest_scorebest_params
0svm0.949360{'C': 1, 'kernel': 'linear'}
1random_forest0.899833{'n_estimators': 10}
2logistic_regression0.920979{'C': 1}
3naive_bayes_gaussian0.806344{}
4naive_bayes_multinomial0.871452{}
5decision_tree0.817474{'criterion': 'entropy'}
\n", 158 | "
" 159 | ], 160 | "text/plain": [ 161 | " model best_score best_params\n", 162 | "0 svm 0.949360 {'C': 1, 'kernel': 'linear'}\n", 163 | "1 random_forest 0.899833 {'n_estimators': 10}\n", 164 | "2 logistic_regression 0.920979 {'C': 1}\n", 165 | "3 naive_bayes_gaussian 0.806344 {}\n", 166 | "4 naive_bayes_multinomial 0.871452 {}\n", 167 | "5 decision_tree 0.817474 {'criterion': 'entropy'}" 168 | ] 169 | }, 170 | "execution_count": 4, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "from sklearn.model_selection import GridSearchCV\n", 177 | "import pandas as pd\n", 178 | "scores = []\n", 179 | "\n", 180 | "for model_name, mp in model_params.items():\n", 181 | " clf = GridSearchCV(mp['model'], mp['params'], cv=5, return_train_score=False)\n", 182 | " clf.fit(digits.data, digits.target)\n", 183 | " scores.append({\n", 184 | " 'model': model_name,\n", 185 | " 'best_score': clf.best_score_,\n", 186 | " 'best_params': clf.best_params_\n", 187 | " })\n", 188 | " \n", 189 | "df = pd.DataFrame(scores,columns=['model','best_score','best_params'])\n", 190 | "df" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": {}, 196 | "source": [ 197 | "**For me the winner is svm (C=1, kernel=linear) with 94.93% score. It could be different for you as I have limited my parameters to be certain values only**" 198 | ] 199 | } 200 | ], 201 | "metadata": { 202 | "kernelspec": { 203 | "display_name": "Python 3", 204 | "language": "python", 205 | "name": "python3" 206 | }, 207 | "language_info": { 208 | "codemirror_mode": { 209 | "name": "ipython", 210 | "version": 3 211 | }, 212 | "file_extension": ".py", 213 | "mimetype": "text/x-python", 214 | "name": "python", 215 | "nbconvert_exporter": "python", 216 | "pygments_lexer": "ipython3", 217 | "version": "3.7.3" 218 | } 219 | }, 220 | "nbformat": 4, 221 | "nbformat_minor": 2 222 | } 223 | --------------------------------------------------------------------------------