├── .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 |
10 |
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 |
28 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
48 |
60 |
61 |