├── data ├── sample.txt └── index.html ├── requirements.txt ├── images ├── indus-script.png ├── gartner-analytics.gif └── ds-venn-diagram-booz-allen.png ├── scripts └── ctr_program.py ├── LICENSE ├── README.md ├── .gitignore ├── 00-table-of-contents.ipynb ├── 02-0-computer-programming-for-digital-marketers.ipynb ├── 02-1-python-programming-for-digital-maketers.ipynb ├── 01-introduction-to-data-science-digital-marketers.ipynb ├── 02-3-how-to-use-3rd-party-python-packages.ipynb └── 02-2-introduction-to-python-digital-marketers.ipynb /data/sample.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.24.2 2 | jupyterlab==3.6.3 -------------------------------------------------------------------------------- /data/index.html: -------------------------------------------------------------------------------- 1 | This is my titleWelcome to my website on Digital Marketing! -------------------------------------------------------------------------------- /images/indus-script.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serpwings/data-science-for-digital-marketers/HEAD/images/indus-script.png -------------------------------------------------------------------------------- /scripts/ctr_program.py: -------------------------------------------------------------------------------- 1 | ctr_seowings = 4.2 2 | ctr_serowings = 3.9 3 | avg_ctr = (ctr_seowings + ctr_serowings)/2 4 | print (avg_ctr) -------------------------------------------------------------------------------- /images/gartner-analytics.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serpwings/data-science-for-digital-marketers/HEAD/images/gartner-analytics.gif -------------------------------------------------------------------------------- /images/ds-venn-diagram-booz-allen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serpwings/data-science-for-digital-marketers/HEAD/images/ds-venn-diagram-booz-allen.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 SERP Wings 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data Science for Digital Marketers 2 | 3 | These are the lecture notes (Jupyter Notebooks) for an online Data Science for Digital Marketers course by SEO Wings. 4 | 5 | # How To Read 6 | 7 | ## GitHub 8 | 9 | You can read them online at GitHub. Click on an individual notebook, and GitHub will render it in HTML for your reading. 10 | 11 | ## Binder 12 | 13 | You can read content of this book online at Binder website [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/serpwings/data-science-for-digital-marketers/HEAD) 14 | 15 | 16 | # How to Run 17 | 18 | You can clone this repository into the local computer (or Google Colab) and run individual files. 19 | 20 | 21 | ## Issues and Questions 22 | 23 | - If you find any issue (typo, bug, error, mistake) on this repository content, please create an issue. I will answer it here so that future readers can also benefit from this. 24 | - If you have modified any content, then feel free to submit a pull request. After verifying your changes, we will merge them into the main repository. 25 | - I have set up a Discussion on this repository. Use it to discuss any topic or polls, etc. 26 | 27 | 28 | ## License 29 | Creative Commons License 30 | 31 | - Data Science for Digital Marketers by Dr. Faisal Shahzad is licensed under a Creative Commons Attribution 4.0 International License. 32 | - Code Snippets are released under MIT License (See license file) 33 | 34 | ## Contact 35 | 36 | serowingsorg at gmail.com -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 9*.ipynb 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | pip-wheel-metadata/ 25 | share/python-wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | db.sqlite3-journal 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | .python-version 87 | 88 | # pipenv 89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 92 | # install all needed dependencies. 93 | #Pipfile.lock 94 | 95 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 96 | __pypackages__/ 97 | 98 | # Celery stuff 99 | celerybeat-schedule 100 | celerybeat.pid 101 | 102 | # SageMath parsed files 103 | *.sage.py 104 | 105 | # Environments 106 | .env 107 | .venv 108 | env/ 109 | venv/ 110 | ENV/ 111 | env.bak/ 112 | venv.bak/ 113 | 114 | # Spyder project settings 115 | .spyderproject 116 | .spyproject 117 | 118 | # Rope project settings 119 | .ropeproject 120 | 121 | # mkdocs documentation 122 | /site 123 | 124 | # mypy 125 | .mypy_cache/ 126 | .dmypy.json 127 | dmypy.json 128 | 129 | # Pyre type checker 130 | .pyre/ 131 | -------------------------------------------------------------------------------- /00-table-of-contents.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b7f2c5f3-af84-4c2c-8c8e-1fcec3bac5cf", 6 | "metadata": {}, 7 | "source": [ 8 | "# Table of Contents" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "d0ed4c57-1787-4552-bb87-eb7bb4c471f6", 14 | "metadata": { 15 | "tags": [] 16 | }, 17 | "source": [ 18 | "\n", 19 | "## 1. [Introduction to Data Science for Digital Marketers](01-introduction-to-data-science-digital-marketers.ipynb)\n", 20 | "- What is Data?\n", 21 | "- What is Data Science?\n", 22 | "- Data Sources for Digital Marketing?\n", 23 | "- What you need to know?\n", 24 | "\n", 25 | "## 2. Introduction to Python Progrmaming for Digital Marketers \n", 26 | "\n", 27 | "- [Coomputer Programming for Digital Marketers](02-0-computer-programming-for-digital-marketers.ipynb)\n", 28 | "- [Python Prgramming for Digital Marketers](02-1-python-pgoramming-for-digital-maketers.ipynb)\n", 29 | "- [Introduction to Python for Digital Maketers](02-2-introduction-to-python-digital-marketers.ipynb)\n", 30 | "- [How to Use 3rd Party Python Packages?](02-3-how-to-use-3rd-party-python-packages.ipynb)\n", 31 | "\n", 32 | "## 3. Git and GiHub for Digital Marketers\n", 33 | "- Basic Concepts\n", 34 | "- Use Cases\n", 35 | "- Data Handling\n", 36 | "- Branching\n", 37 | "- Fork, Commit, Merge\n", 38 | "\n", 39 | "## 4. Python for Digital Marketers\n", 40 | "- Numpy\n", 41 | "- Pandas\n", 42 | " \n", 43 | "## 5. Data Munging\n", 44 | "- Data Refinement\n", 45 | "- Web scraping \n", 46 | "- APIs\n", 47 | "- Big Data\n", 48 | "\n", 49 | "## 6. Data Visualization\n", 50 | "- Matplotlib\n", 51 | "- 1D Plots\n", 52 | "- 2D Plots\n", 53 | "- 3D Plots\n", 54 | "\n", 55 | "## 7. Classification\n", 56 | "- k-nearest Neighbors\n", 57 | "- Decision Trees\n", 58 | "- Support Vector Machines\n", 59 | "- Neural Networks\n", 60 | "\n", 61 | "## 8. Regression\n", 62 | "\n", 63 | "## 9. Clustering\n", 64 | "\n", 65 | "## 10. Natural Language Processing\n", 66 | "- Keywords\n", 67 | "- Feature Engineering\n", 68 | "- Sentiment Analysis\n", 69 | "\n", 70 | "## 11. Network analysis\n", 71 | "- Social Networks\n", 72 | " - Twitter\n", 73 | "- Website Links\n", 74 | " - Internal\n", 75 | " - External\n", 76 | "\n", 77 | "## 12. CASE STUDIES\n", 78 | "1. SEO Traffic Analysis\n", 79 | "2. Analyzing advertising campaign performance\n", 80 | "3. Analyzing competitor data and website traffic\n", 81 | "4. YouTube video and campaign performance\n", 82 | "5. Analyze Amazon (PPC/PL) Advertising Campaign\n", 83 | "6. Optimize Amazon PPC campaigns\n", 84 | "7. Customer Segmentation and Profiling\n", 85 | "8. Sentiment analysis of customer feedback using NLP\n", 86 | "9. A/B testing for Marketing Optimization\n", 87 | "\n", 88 | "## Appendix 1: Mathematics Premier\n", 89 | "## Appendix 2: Statistics Premier" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "id": "6174e7e4-07f0-465b-97d8-61c68f6155ae", 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "Python 3 (ipykernel)", 104 | "language": "python", 105 | "name": "python3" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 3 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython3", 117 | "version": "3.10.11" 118 | } 119 | }, 120 | "nbformat": 4, 121 | "nbformat_minor": 5 122 | } 123 | -------------------------------------------------------------------------------- /02-0-computer-programming-for-digital-marketers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1e0e5959-7afd-4dcc-a8c5-fa2f07d9e377", 6 | "metadata": {}, 7 | "source": [ 8 | "## Introduction to Computer Programming\n", 9 | "\n", 10 | "Python has gained popularity in the last decade due to several reasons, such as ease of learning the programming language, versatile fields of application, a huge package ecosystem, and more importantly, because it is the de facto language for data science and machine learning.\n", 11 | "\n", 12 | "Digital marketers have been leveraging these developments to improve their marketing campaigns and gain business insights to improve their growth.\n", 13 | "\n", 14 | "In this chapter, we will discuss how to get ready with Python. Throughout, we will use vanilla Python from the python.org website. You will also learn \"How to set up Python on your operating system of choice?\" and \"How to setup Jupyter-Lab\". You should be able to conduct all the exercises on \"Jupyter-Lab\".\n", 15 | "\n", 16 | "## How Computer Works?\n", 17 | "- Examples of 7 Segement\n", 18 | "- Switches and Binary System\n", 19 | "- How Content is renderd on Screen?\n", 20 | "- How Operating Works?\n", 21 | " - What are differnet operating Systems?\n", 22 | " - Windows\n", 23 | " - Linux\n", 24 | " - BSD\n", 25 | " - Android\n", 26 | " - OSX\n", 27 | " - Why we have different operating Systems?\n", 28 | " - How to Choose Operating Sytem?\n", 29 | "\n", 30 | "## What is a Computer Program?\n", 31 | "\n", 32 | "- Set of Instructions to perform any task\n", 33 | "- Types of Computer Programs\n", 34 | " - Application Programs\n", 35 | " - Chrome Browser\n", 36 | " - MS OFfice (Excel & Power Points)\n", 37 | " - Tailor Made/Custom Programs\n", 38 | " - Zoom\n", 39 | " - Grammerly\n", 40 | " - Quilbot\n", 41 | " - Screaming Frog\n", 42 | "\n", 43 | "## Computer Programming and User Interfaces\n", 44 | "\n", 45 | "- CLI (Command Line)\n", 46 | "- GUI (Graphical User Interface)\n", 47 | "- chatUX\n", 48 | "\n", 49 | "## What is a Programming Language?\n", 50 | "\n", 51 | "Language is a way to communicate with others. Like communication between humans, we also need a way to communicate with computers and machines. However, machines only understand bits and bytes, and it is hard to program with individual bits.\n", 52 | "\n", 53 | "\n", 54 | "To overcome this, computer scientists have developed programming languages to communicate with and give instructions to a computer. These languages have been divided into several categories.\n", 55 | "\n", 56 | "\n", 57 | "### Lower Level Programming Languages\n", 58 | "\n", 59 | "- Bits\n", 60 | "- Assembly Language\n", 61 | "\n", 62 | "### Higher Level Programming Languages\n", 63 | "\n", 64 | "A human can understand and interpret these languages without getting too deep into individual bits. Many programming languages offer features, e.g., a garbage collector, type casting, etc., without any additional effort.\n", 65 | "    \n", 66 | "There are thousands of languages invented in computing history. Most notable are Lisp and FORTRAN from early computer programming days. More languages have been developed in recent years, but they still borrow programming concepts from those old computer languages invented in the 1960s and 1970s.\n", 67 | "\n", 68 | "It is no wonder that modern programming languages like Python, Javascript, Ruby, Perl, and Closure are highly influenced by LiSP which was invented as a List Processing language.\n", 69 | "- Task Oreinted\n", 70 | "- General Purpose \n", 71 | "\n", 72 | "## Python as a Programming Language\n", 73 | "\n", 74 | "Python is a high-level programming language. It is very easy to learn and has human-readable syntax. Python scripts can be executed in almost all operating systems without additional configuration, e.g., Windows, Linux, Unix, Android, and even in browsers. \n", 75 | "\n", 76 | "Python has several advantages over its rivals and competitors, e.g., MATLAB, Julia, and R-Lang. Python can be used in different areas.\n", 77 | "\n", 78 | "### Web Development \n", 79 | "\n", 80 | "You can use Python for web development. It is possible to use Python for both dynamic and static \n", 81 | "\n", 82 | "Plone, a python-based content management system, can be used for regular content management system tasks. You can use Jinja2 as a templating engine to generate HTML pages. A plethora of open-source static site generators are written in Python, e.g., Pelican, Lektor, and MkDocs.\n", 83 | "\n", 84 | "Flask and FASTAPI are quite popular for API development tasks in Python. You can also deploy them as lambda functions of servers, e.g., Vercel.\n", 85 | "\n", 86 | "Flask, Django, Bottle, and Web2py are popular web development frameworks for Python users.\n", 87 | "\n", 88 | "If you are looking for a Python alternative to Javascript to run scripts in a browser, then you will love the Brython Python package.\n", 89 | "\n", 90 | "\n", 91 | "### App Development\n", 92 | "\n", 93 | "Python can be used to create desktop and mobile applications (for Android and Apple). Kivy is the most popular GUI framework for such tasks. You can also use QML for app development tasks.\n", 94 | "\n", 95 | "### Application Programming\n", 96 | "\n", 97 | "You can create application programs in Python, e.g., Dropbox, Spotify, and many others.\n", 98 | "\n", 99 | "\n", 100 | "### Taks Automation \n", 101 | "\n", 102 | "Most famous software also offers plugin development for extending functionalities using Python scripting, e.g., Blender for 3D or Excel with Python using the xlswings Python Package.\n", 103 | "\n" 104 | ] 105 | } 106 | ], 107 | "metadata": { 108 | "kernelspec": { 109 | "display_name": "Python 3 (ipykernel)", 110 | "language": "python", 111 | "name": "python3" 112 | }, 113 | "language_info": { 114 | "codemirror_mode": { 115 | "name": "ipython", 116 | "version": 3 117 | }, 118 | "file_extension": ".py", 119 | "mimetype": "text/x-python", 120 | "name": "python", 121 | "nbconvert_exporter": "python", 122 | "pygments_lexer": "ipython3", 123 | "version": "3.10.11" 124 | } 125 | }, 126 | "nbformat": 4, 127 | "nbformat_minor": 5 128 | } 129 | -------------------------------------------------------------------------------- /02-1-python-programming-for-digital-maketers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ed120b55-4719-4b5c-9b0a-c0e1e3bcd3c9", 6 | "metadata": {}, 7 | "source": [ 8 | "## Why Python for Digital Marketing?\n", 9 | "\n", 10 | "Digital marketers can use Python for \n", 11 | "\n", 12 | "- Collecting data from multiple sources\n", 13 | "- Cleaning raw data\n", 14 | "- Write scripts and programs to extract useful insights.\n", 15 | "- Digital marketers can write apps using the Kivy Framework.\n", 16 | "- Digital marketers can automate their website development and deployment tasks by leveraging the power of Python." 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "ea14b915-c1be-45b0-a86e-2fe1bad5461e", 22 | "metadata": {}, 23 | "source": [ 24 | "## How To Setup Python?\n", 25 | "\n", 26 | "Python has evolved over the last decade. Installing any recent version of Python is very simple, and you can install it with the default wizard.\n", 27 | "\n", 28 | "Some operating systems will include it by default, e.g., Apple OS X and Linux distributions. However, on Windows, you have to install it yourself.\n", 29 | "\n", 30 | "The Python interpreter was originally written in C, and CPython is the reference implementation for this purpose. There is another Python-based implementation known as PyPy. For most cases, you will only come across CPython, and the default Python distribution is more than enough for your tasks." 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "id": "3cd3f71d-8e10-4af8-b569-7dc9d3df230e", 36 | "metadata": {}, 37 | "source": [ 38 | "### Download Python\n", 39 | "\n", 40 | "Basic Python, also known as Vanilla Python, is available from the official Python website (python.org/downloads). However, being an open-source programming language, there are several other distributions (backed by commercial companies) available for download. It is important to understand the differences and choose the appropriate distribution for your use cases.\n", 41 | "\n", 42 | "- (Vanilla) Python\n", 43 | "- Anaconda\n", 44 | "- WinPython\n", 45 | "- Active Python\n", 46 | "- Embedded Python, e.g., MicroPython" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "id": "7c23cf72-7fc3-4731-b95f-39fb3e59fdfb", 52 | "metadata": {}, 53 | "source": [ 54 | "### Install Python\n", 55 | "\n", 56 | "You can download Python from relevant Python distributions. For this course, you only need to download Python 3.10.11 from the official Python distribution website: https://www.python.org/downloads/release/python-31011/. Scroll down to the bottom of the page and download it for your operating system. " 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "8d75bae9-5728-49f3-84ba-47d1b0623b73", 62 | "metadata": {}, 63 | "source": [ 64 | "#### Windows\n", 65 | "For Windows, most of you will probably need to download **Windows installer (64-bit)**. \n", 66 | "Click on this installer and follow the wizard. On the Installer start page, do not forget to check the checkbox for Add to System Path.\n", 67 | "Keep clicking \"next,\" and your Python will be installed." 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "id": "056518b3-8ac5-4049-8f26-49cd37124c7d", 73 | "metadata": {}, 74 | "source": [ 75 | "#### Linux/Unix\n", 76 | "\n", 77 | "Python will be the default language for most Linux and Unix distributions. If your Python version is outdated and you want to update it, then follow the guidelines from your respective Linux distribution." 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "2c700d93-ce77-41f0-9742-a5d35c9d0d2e", 83 | "metadata": {}, 84 | "source": [ 85 | "#### OSX\n", 86 | "\n", 87 | "Mac OS X will come pre-installed with the Python version. If you need to install any specific version, then please download it from https://www.python.org/downloads/macos/. You might want to explore more options with homebrew and other managers." 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "4c355708-1568-4203-8d9d-d63e48179a6c", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Mobile Phone\n", 96 | "You can also install Python on your mobile phone for learning on the go. Go to the respective app store and search for Python keywords. \n", 97 | "\n", 98 | "- Google Play\n", 99 | "On the Google Play store, you will find relevant apps, e.g., Pydroid. I have tested Pydroid, and it works like a charm.\n", 100 | "\n", 101 | "- Apple Store - IOS\n", 102 | "On the Apple App Store, you will find apps such as Python3IDE and Pyto. I have not tried these apps by myself, so this is not a formal recommendation." 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "id": "09a58a87-c5de-4c82-abc7-4030cf3e44b1", 108 | "metadata": {}, 109 | "source": [ 110 | "## What is Python Environment?\n", 111 | "\n", 112 | "- Why we need Vitual Environment?\n", 113 | "- What are Vitual Environment?\n", 114 | " - venv\n", 115 | " - conda\n", 116 | "- How to Create Virutal environment?\n", 117 | "- How to activate Virtual Environment? \n", 118 | "- How to deactivate virtual environment?" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "id": "9dbed3ba-e4f1-411e-bc50-b90a96bea847", 124 | "metadata": {}, 125 | "source": [ 126 | "## What are package managers?\n", 127 | "\n", 128 | "### PIP\n", 129 | "We will only use this one, which is popular with standard Python.\n", 130 | "\n", 131 | "### Conda\n", 132 | "\n", 133 | "Conda is also a package manager and is used as the default backend for Anaconda.\n", 134 | "\n", 135 | "### PIPEnv\n", 136 | "\n", 137 | "It uses PIP and the virtual environment as a single command.\n", 138 | "\n", 139 | "### Peotry\n", 140 | "\n", 141 | "Another package manager, which has gained popularity in recent years. " 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "id": "3228ba4b-00ca-4f9a-974e-2a7421e51b3e", 147 | "metadata": {}, 148 | "source": [ 149 | "## What are Python Packages?\n", 150 | "\n", 151 | "- like apps with additional feature\n", 152 | "\n", 153 | "### Offical Python Packages\n", 154 | " - All Packages are avialble on https://pypi.org/ which contains metadata/information about the python packages.\n", 155 | " - All Package files are stored and download from https://files.pythonhosted.org/\n", 156 | " - You can install it using `pip install package-name`\n", 157 | "\n", 158 | "\n", 159 | "### Conda Package Distribution \n", 160 | "- Conda pacakges are available on https://conda-forge.org/feedstock-outputs/\n", 161 | "- You can install them using `conda install package-name`" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "id": "9db42cbd-9a3c-4cf0-bb8c-fe452897a231", 167 | "metadata": {}, 168 | "source": [ 169 | "## What is iPython?\n", 170 | "\n", 171 | "- Vanila Python Command Line is not interactive\n", 172 | "- To make interactive use \n", 173 | "\n", 174 | "### IPython Project\n", 175 | "- Development of iPython (Qt Widget, PyQMZ, Paralell Computing, Sockets, etc)\n", 176 | "- Python backend to the Jupyter Notebook (kernel)\n", 177 | "- interactive Python shell. \n", 178 | " \n", 179 | "### The Big Split - Birth of Jupyter\n", 180 | "\n", 181 | "Julia, Python and R (JuPyterR) \n", 182 | "\n", 183 | "- Jupyter Note Book\n", 184 | "- Jupyter-lab (this is main)\n", 185 | "- Code reproducebalitiy " 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "id": "d5eede5b-1608-4b63-bab7-f1e6ac68b1b6", 191 | "metadata": {}, 192 | "source": [ 193 | "## Introduciton to Jupyter-Lab\n", 194 | "\n", 195 | "1. Raw \n", 196 | "2. Markdown\n", 197 | "3. Code (python)\n", 198 | "\n", 199 | "### Help in Jupyter Lab\n", 200 | "\n", 201 | "you have to use ?\n", 202 | "\n", 203 | "\n", 204 | "```python\n", 205 | "min?\n", 206 | "```\n", 207 | "\n", 208 | "Additional commands will be added here later." 209 | ] 210 | } 211 | ], 212 | "metadata": { 213 | "kernelspec": { 214 | "display_name": "Python 3 (ipykernel)", 215 | "language": "python", 216 | "name": "python3" 217 | }, 218 | "language_info": { 219 | "codemirror_mode": { 220 | "name": "ipython", 221 | "version": 3 222 | }, 223 | "file_extension": ".py", 224 | "mimetype": "text/x-python", 225 | "name": "python", 226 | "nbconvert_exporter": "python", 227 | "pygments_lexer": "ipython3", 228 | "version": "3.10.11" 229 | } 230 | }, 231 | "nbformat": 4, 232 | "nbformat_minor": 5 233 | } 234 | -------------------------------------------------------------------------------- /01-introduction-to-data-science-digital-marketers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b7f2c5f3-af84-4c2c-8c8e-1fcec3bac5cf", 6 | "metadata": {}, 7 | "source": [ 8 | "# Introduction" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "d0ed4c57-1787-4552-bb87-eb7bb4c471f6", 14 | "metadata": {}, 15 | "source": [ 16 | "Data science plays a crucial role in digital marketing by providing insights and predictions that help businesses make informed decisions. It involves collecting, processing, analyzing and interpreting large amounts of data to uncover patterns and trends.\n", 17 | "\n", 18 | "Let's explore all the concepts one-by-one both with historical and modern examples." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "id": "96ed13b6-347d-4a78-a1e2-a2af38bc5ecf", 24 | "metadata": { 25 | "tags": [] 26 | }, 27 | "source": [ 28 | "## What is Data?\n", 29 | "\n", 30 | "- Charaters\n", 31 | "- Symbols\n", 32 | "- Quanities\n", 33 | "- Sounds\n", 34 | "- Electrical Singals\n", 35 | " - Bits\n", 36 | " - Text\n", 37 | " - images\n", 38 | " - Audio\n", 39 | " - Video \n", 40 | " - numbers " 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "5828d6b6-5bf6-4bac-a393-7e49aed0d723", 46 | "metadata": { 47 | "tags": [] 48 | }, 49 | "source": [ 50 | "## How Data Is Stored?\n", 51 | "\n", 52 | "- Cave times?\n", 53 | "- leather Skin?\n", 54 | "- Paper?\n", 55 | "- Recording Mediums e.g. Drives,\n", 56 | "- Data Bases" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "6bfc2a64-d30a-40d9-9ad2-e7913aa301fa", 62 | "metadata": { 63 | "tags": [] 64 | }, 65 | "source": [ 66 | "## Data Dimensions\n", 67 | "\n", 68 | "Dimensions are the attirbutes of your data to help answers the questions usually thourgh aggregation/summarization.\n", 69 | "\n", 70 | "- Spatial\n", 71 | "- Temporal\n", 72 | "- weight/length/temperatur\n", 73 | "- Customer\n", 74 | "- Product\n", 75 | "\n", 76 | "Take an example from Google Trends\n", 77 | "\n", 78 | "https://trends.google.de/trends/explore?q=Data%20Science&date=now%201-d&geo=US&hl=en-US" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "id": "5fda1519-c547-4b18-a908-bcddad94753a", 84 | "metadata": {}, 85 | "source": [ 86 | "## What is Data Encoding and Decoding?" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "id": "1f70c935-3864-4967-8e04-206b2f264db5", 92 | "metadata": {}, 93 | "source": [ 94 | "- Cave Images\n", 95 | "- Military Signs\n", 96 | "- Encoding and Decoding of Indus Valley Civilization Scripts by Prof. Ahmad Hassan Dani" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "id": "26d19eb0-5c94-4597-ac66-9699fa57bd75", 102 | "metadata": { 103 | "tags": [] 104 | }, 105 | "source": [ 106 | "\n", 107 | "\n", 108 | "Source: https://www.thearchaeologist.org/blog/why-we-still-cant-crack-the-indus-script" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "id": "6cca57d2-f151-4713-8b01-7e4b97a12c13", 114 | "metadata": { 115 | "tags": [] 116 | }, 117 | "source": [ 118 | "## Professions around Data\n", 119 | "\n", 120 | "Data directly relates to humans, whether for Humans or by Humans. This results in the development of new professions which deals with data, including but not limited to \n", 121 | "\n", 122 | "- Data Engineer \n", 123 | " - data handling- ETL/ELT\n", 124 | " - Requires Technical Skills \n", 125 | " - Data handling/Storing/processing (DBs)\n", 126 | "- Data Analyst\n", 127 | " - Analyze Data\n", 128 | " - Story Telling\n", 129 | "- Data Scientist\n", 130 | " - Strong Analytical Skill\n", 131 | " - Mathematics/Statistics/Programming (R/Python/Julia/Matlab)\n", 132 | " - Machine Learning/AI" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "id": "a419f714-a38a-425b-b755-1152bc38a729", 138 | "metadata": {}, 139 | "source": [ 140 | "## What is Data Science?\n", 141 | "\n", 142 | "Scientific Study of the Data \n", 143 | "- domain specific insights (business, technological advancement,)\n", 144 | "- story telling" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "id": "ac2c73e8-659a-44f5-87f3-0b303a73673e", 150 | "metadata": { 151 | "tags": [] 152 | }, 153 | "source": [ 154 | "\n", 155 | "\n", 156 | "Source: Booz Allen - See https://www.researchgate.net/publication/258698880_The_Field_Guide_to_Data_Science" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "325ad611-c0f6-4e48-a08b-33f2e2a4278d", 162 | "metadata": {}, 163 | "source": [ 164 | "## Data Scientist Skills\n", 165 | "\n", 166 | "- Numerical (Statistics/Mathematics) \n", 167 | "- Computitional (Programming/Scripting/Computer Affine)\n", 168 | "- Domain Specific Knowledge (DM, Geo, Business, ...)\n", 169 | " - Why minium knowledge is very important e.g. How to Optimize CTR or Dwell Time?\n", 170 | " \n", 171 | "- A Data Scientist should have\n", 172 | " - Scientifc Mindset (Computer/Analytics)\n", 173 | " - Curious (Data Management)\n", 174 | " - Creative (Graphs)\n", 175 | " - pragramatic \n", 176 | " - Business Thinking /DM\n", 177 | " " 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "id": "50d170cb-7276-45cc-b148-a7192e10a2c1", 183 | "metadata": {}, 184 | "source": [ 185 | "# Numerical Skills (Minimum)\n", 186 | "- Statistics (Best would be to know 12th Grade Statistics) \n", 187 | " - Measure of Central Tendency\n", 188 | " - Dispresion\n", 189 | " - Probability\n", 190 | " - Normal Distribution\n", 191 | " - Bayes Theorem\n", 192 | "- Mathematics\n", 193 | " - Matrices\n", 194 | " - Calcuus\n", 195 | " - Differentiation\n", 196 | " - Partial Derivatives" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "id": "8c16070c-5d99-4351-a5f5-c8a61f7b3219", 202 | "metadata": {}, 203 | "source": [ 204 | "## Computitional Skills (Minimum)\n", 205 | "\n", 206 | "- Computer Affine\n", 207 | " - Windows (Can do most of the tasks independently)\n", 208 | " - Linux/Unix (Best)\n", 209 | " - Bash/Scripting (Awesome)\n", 210 | "- Programming\n", 211 | " - Basic Knowlege\n", 212 | " - Python/MATLAB/Julia/R\n", 213 | " - Functionial Programming\n", 214 | "- Version Control System\n", 215 | " - SVN/GIT (Git is preffered)\n", 216 | " - Manage \n", 217 | " - Code\n", 218 | " - Content\n", 219 | " - Data (Small and Large Files)" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "id": "1a5e9fff-f79b-4cae-ae16-050a83feb877", 225 | "metadata": {}, 226 | "source": [ 227 | "## Domain Specific Skills (DM)\n", 228 | "\n", 229 | "- Know Possible Data Source\n", 230 | " - Adwords\n", 231 | " - Google Analytics or any other anlytics \n", 232 | " - PPC Data from FB/Google/Amazon\n", 233 | " - from other Paid tools (Semrush, Ahrefs, Moz)\n", 234 | "- How Website Works?\n", 235 | " - Basic knowledge of HTML/CSS/JS\n", 236 | " - Hosting/CDN/DNS\n", 237 | "- Keywords/Niches\n", 238 | "- Terminologies\n", 239 | " - CTR\n", 240 | " - Dwell TIME\n", 241 | " - CPM\n", 242 | " - PPC\n", 243 | " - ...\n" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "id": "9941e3bb-32d5-4930-883b-a5910766a983", 249 | "metadata": { 250 | "tags": [] 251 | }, 252 | "source": [ 253 | "## How to Analyze Data?\n", 254 | "\n", 255 | "- Descriptive\n", 256 | " - What Actually Happend?\n", 257 | " - e.g. Sales through various Channles, or Click through Rate of a YouTube video\n", 258 | " - Examples\n", 259 | " - Descriptive Statistics\n", 260 | " - Data Clustering\n", 261 | " - Business Intellegence\n", 262 | "- Diagnositc\n", 263 | " - Why Something Happend?\n", 264 | " - More drill down on data.\n", 265 | " - Why Sales dropped for a specific channle. Or why Click through rate of a specific youtube video is higher?\n", 266 | " - Examples\n", 267 | " - Business Intellegence\n", 268 | " - Sensivity Analysis\n", 269 | " - Desing of Experiments\n", 270 | "- Predictive\n", 271 | " - What might happen in future (prediction)\n", 272 | " - requres larger datasets\n", 273 | " - Which channel will bring more traffic?. \n", 274 | " - Examples\n", 275 | " - Regression (linear and Logistic)\n", 276 | " - Neural Networks\n", 277 | " - Support Vector Machines\n", 278 | "- Perspective\n", 279 | " - What you should do? i.e. What actions are required?\n", 280 | " - Which specific youtube video topic which will bring more subscriber or views or sales\n", 281 | " - Examples\n", 282 | " - Simulations (mont carlo simulation)\n", 283 | " - Optimization (linear or non linear programming)" 284 | ] 285 | }, 286 | { 287 | "cell_type": "markdown", 288 | "id": "74d0691f-850f-49a7-87c1-df043a2605b5", 289 | "metadata": { 290 | "tags": [] 291 | }, 292 | "source": [ 293 | "\n", 294 | "\n", 295 | "Source: Gartner - https://www.gartner.com/en/newsroom/press-releases/2014-10-21-gartner-says-advanced-analytics-is-a-top-business-priority" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "id": "2ea9db5e-6ea9-452a-86a1-f4e155fc5b58", 301 | "metadata": {}, 302 | "source": [ 303 | "## Data Source in DM\n", 304 | "\n", 305 | "- Search Console Data \n", 306 | " - Google\n", 307 | " - Bing\n", 308 | " - ...\n", 309 | "- Advertisment Data\n", 310 | " - AdWords\n", 311 | " - Amazon\n", 312 | " - Pinterest\n", 313 | " - Shopify (Optional)\n", 314 | " - ...\n", 315 | "- Conversion Data\n", 316 | " - Sales Data\n", 317 | " - Analytics Data (Google)\n", 318 | " - ...\n", 319 | "- Competitor Data\n", 320 | " - Semrush\n", 321 | " - Ahrefs\n", 322 | " - Competitor Website\n", 323 | " - ..." 324 | ] 325 | } 326 | ], 327 | "metadata": { 328 | "kernelspec": { 329 | "display_name": "Python 3 (ipykernel)", 330 | "language": "python", 331 | "name": "python3" 332 | }, 333 | "language_info": { 334 | "codemirror_mode": { 335 | "name": "ipython", 336 | "version": 3 337 | }, 338 | "file_extension": ".py", 339 | "mimetype": "text/x-python", 340 | "name": "python", 341 | "nbconvert_exporter": "python", 342 | "pygments_lexer": "ipython3", 343 | "version": "3.10.11" 344 | } 345 | }, 346 | "nbformat": 4, 347 | "nbformat_minor": 5 348 | } 349 | -------------------------------------------------------------------------------- /02-3-how-to-use-3rd-party-python-packages.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "954f40fe-440f-4d80-8043-4168ee51ab32", 6 | "metadata": {}, 7 | "source": [ 8 | "# Plyaing with Python Code\n", 9 | "\n", 10 | "Since, you have already aquired basic understanding of python and its core concepts for data handling and basic maniupluation. You might be wondering that \n", 11 | "\n", 12 | "- What is Python Standard Library?\n", 13 | "- How to include 3rd party packages in your python projects\n", 14 | "- what are the best practaices to organize your python projects\n", 15 | "- How to distribute you Python code to others.\n", 16 | "\n", 17 | "Answers to these questiions are elaborated in the following sections." 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "id": "12756103-41d7-4d7b-a9b9-ecfa9172b77a", 23 | "metadata": {}, 24 | "source": [ 25 | "## How to import Python Packages?\n", 26 | "\n", 27 | "Python code can be organized into modules, Packages or indvidual Scripts. This code can be written by your, 3rd party or may be the part of Python standard library. When importing these modules you have sevreal options\n", 28 | "\n", 29 | "- Full import\n", 30 | " - import pysitemap\n", 31 | "\n", 32 | "- Import a desired Sub-Modules\n", 33 | " - from pysitemap import Sitemap\n", 34 | " \n", 35 | "- Import all Sub Modueles\n", 36 | " - from pysitemap import *" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "986bc997-ce6b-447b-9d40-31da808df1f1", 42 | "metadata": {}, 43 | "source": [ 44 | "## Python Standard Library\n", 45 | "\n", 46 | "Standard Python, also know as Vanila Python only contains basic functionalities to keep it foot print minimum. However, this minimum installation also contians tons of useful functions, and pcakges which are know as python standard library. This library includes functionalities for data handling, basic manipulation and tons of other algorithms." 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "id": "71786ae6-99c7-46b5-a2b7-2eb0db1b788f", 52 | "metadata": {}, 53 | "source": [ 54 | "## 3rd Party Packages\n", 55 | "\n", 56 | "This standard library has limited functionalities and if you are looking for a function which is not part of standard library then you can install aditional 3rd party library. \n", 57 | "\n", 58 | "Python has a rich collection of 3rd party packages, application interfaces, and modules which allows you to perform custom marketing taks without even writing those functionalities by yourself. For example, if you are interested in numerical calculations, then you can use numpy and pandas python packages. For most of the scintific works with extenstive algorithms, you are good to go with scipy and scikit-* packages. \n", 59 | "\n", 60 | "One of the reason for Python popularity is the wide availablity of such packages. In most of the cases, you will always find out packages for any of your taks.\n", 61 | "\n", 62 | "\n", 63 | "You can isntall 3rd party packages using pip commands. For example if you want to install pysitemaps library which is available at pipy, then you can simply isntall it using following commands." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 7, 69 | "id": "63b15256-967f-4882-ba71-9cf1661a1dc3", 70 | "metadata": { 71 | "tags": [] 72 | }, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "Requirement already satisfied: pysitemaps in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (0.0.6)\n", 79 | "Requirement already satisfied: requests in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from pysitemaps) (2.28.2)\n", 80 | "Requirement already satisfied: beautifulsoup4 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from pysitemaps) (4.12.2)\n", 81 | "Requirement already satisfied: lxml in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from pysitemaps) (4.9.2)\n", 82 | "Requirement already satisfied: soupsieve>1.2 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from beautifulsoup4->pysitemaps) (2.4.1)\n", 83 | "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from requests->pysitemaps) (3.1.0)\n", 84 | "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from requests->pysitemaps) (3.4)\n", 85 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from requests->pysitemaps) (1.26.15)\n", 86 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\admin\\documents\\github\\data-science-for-digital-marketers\\.venv\\lib\\site-packages (from requests->pysitemaps) (2022.12.7)\n" 87 | ] 88 | }, 89 | { 90 | "name": "stderr", 91 | "output_type": "stream", 92 | "text": [ 93 | "\n", 94 | "[notice] A new release of pip is available: 23.1 -> 23.1.2\n", 95 | "[notice] To update, run: python.exe -m pip install --upgrade pip\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "!pip install pysitemaps" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 8, 106 | "id": "acab8206-80cf-4240-bb92-4717161aaee1", 107 | "metadata": { 108 | "tags": [] 109 | }, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "{'parent': {'loc': 'https://www.seowings.org/sitemap.xml', 'lastmod': '2023-05-06', 'urls': [{'loc': 'https://www.seowings.org/static-wordpress/', 'lastmod': '2022-11-18', 'images': []}, {'loc': 'https://www.seowings.org/simply-static-tutorial/', 'lastmod': '2023-03-05', 'images': []}, {'loc': 'https://www.seowings.org/host-wordpress-website-on-netlify/', 'lastmod': '2022-11-19', 'images': []}, {'loc': 'https://www.seowings.org/web-server-log-files/', 'lastmod': '2022-11-27', 'images': []}, {'loc': 'https://www.seowings.org/local-wordpress-hosting-on-virtual-machines/', 'lastmod': '2022-11-20', 'images': []}, {'loc': 'https://www.seowings.org/seoquake-tutorial/', 'lastmod': '2022-11-29', 'images': []}, {'loc': 'https://www.seowings.org/robots-txt/', 'lastmod': '2022-11-27', 'images': []}, {'loc': 'https://www.seowings.org/best-static-website-hosting-services/', 'lastmod': '2023-01-01', 'images': []}, {'loc': 'https://www.seowings.org/static-web-hosting/', 'lastmod': '2023-01-02', 'images': []}, {'loc': 'https://www.seowings.org/competitor-analysis-using-sitemaps/', 'lastmod': '2022-11-19', 'images': []}, {'loc': 'https://www.seowings.org/seo-minion-tutorial/', 'lastmod': '2022-11-22', 'images': []}, {'loc': 'https://www.seowings.org/best-software-for-installing-wordpress-on-localhost/', 'lastmod': '2022-11-24', 'images': []}, {'loc': 'https://www.seowings.org/sitemap-seo/', 'lastmod': '2022-12-17', 'images': []}, {'loc': 'https://www.seowings.org/seo-and-web-hosting/', 'lastmod': '2022-11-21', 'images': []}, {'loc': 'https://www.seowings.org/what-is-a-domain-name/', 'lastmod': '2022-12-02', 'images': []}, {'loc': 'https://www.seowings.org/advantages-of-local-wordpress-hosting/', 'lastmod': '2022-11-15', 'images': []}, {'loc': 'https://www.seowings.org/website-architecture-and-seo/', 'lastmod': '2022-12-01', 'images': []}, {'loc': 'https://www.seowings.org/wordpress/', 'lastmod': '2022-12-14', 'images': []}, {'loc': 'https://www.seowings.org/web-domains/', 'lastmod': '2022-12-13', 'images': []}, {'loc': 'https://www.seowings.org/software/', 'lastmod': '2022-11-19', 'images': []}, {'loc': 'https://www.seowings.org/search-engine-optimization/', 'lastmod': '2022-11-13', 'images': []}, {'loc': 'https://www.seowings.org/static-websites/', 'lastmod': '2022-12-14', 'images': []}, {'loc': 'https://www.seowings.org/research-work/', 'lastmod': '2022-11-28', 'images': []}]}, 'xsl-file': '', 'sub_sitemaps': []}\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "# https://serpwings.com/software/python-sitemaps/\n", 121 | "from pysitemaps import Sitemap, Url, XmlDocument \n", 122 | "\n", 123 | "smp = Sitemap(website_name=\"https://www.seowings.org/\")\n", 124 | "smp.fetch(include_urls=True)\n", 125 | "print(smp.as_dict())" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 9, 131 | "id": "c328949b-f6f3-4b33-9a5d-5423e86b1263", 132 | "metadata": { 133 | "tags": [] 134 | }, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "dict_keys(['parent', 'xsl-file', 'sub_sitemaps'])" 140 | ] 141 | }, 142 | "execution_count": 9, 143 | "metadata": {}, 144 | "output_type": "execute_result" 145 | } 146 | ], 147 | "source": [ 148 | "sitemap.keys()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 10, 154 | "id": "8df0537f-3220-4f06-9d55-e84edd1541c4", 155 | "metadata": { 156 | "tags": [] 157 | }, 158 | "outputs": [ 159 | { 160 | "data": { 161 | "text/plain": [ 162 | "dict_keys(['loc', 'lastmod', 'urls'])" 163 | ] 164 | }, 165 | "execution_count": 10, 166 | "metadata": {}, 167 | "output_type": "execute_result" 168 | } 169 | ], 170 | "source": [ 171 | "sitemap['parent'].keys()" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 11, 177 | "id": "13ee2c8d-d501-4d54-b520-5026572bffa1", 178 | "metadata": { 179 | "tags": [] 180 | }, 181 | "outputs": [ 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "list" 186 | ] 187 | }, 188 | "execution_count": 11, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "type(sitemap['parent']['urls'])" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 13, 200 | "id": "d309b0ca-0a0b-4bd5-8e2c-d4ce59420449", 201 | "metadata": { 202 | "tags": [] 203 | }, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/', 'lastmod': '2023-03-19', 'images': []}\n", 210 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/robots-txt/', 'lastmod': '2023-03-19', 'images': []}\n", 211 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/schema-checker/', 'lastmod': '2023-03-19', 'images': []}\n", 212 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/user-agent/', 'lastmod': '2023-03-19', 'images': []}\n", 213 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/user-details/', 'lastmod': '2023-03-19', 'images': []}\n", 214 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/webpage-metadata/', 'lastmod': '2023-03-19', 'images': []}\n", 215 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/webpage-urls/', 'lastmod': '2023-03-19', 'images': []}\n", 216 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/whois-checker/', 'lastmod': '2023-03-19', 'images': []}\n", 217 | "{'loc': 'https://serpwings.com/online-seo-tools/web-tools/wp-details/', 'lastmod': '2023-03-19', 'images': []}\n", 218 | "{'loc': 'https://serpwings.com/online-seo-tools/sitemaps/', 'lastmod': '2023-03-19', 'images': []}\n", 219 | "{'loc': 'https://serpwings.com/online-seo-tools/sitemaps/sitemap-finder/', 'lastmod': '2023-03-19', 'images': []}\n", 220 | "{'loc': 'https://serpwings.com/online-seo-tools/sitemaps/sitemap-details/', 'lastmod': '2023-03-19', 'images': []}\n", 221 | "{'loc': 'https://serpwings.com/online-seo-tools/text-processing/', 'lastmod': '2023-03-19', 'images': []}\n", 222 | "{'loc': 'https://serpwings.com/online-seo-tools/text-processing/url-cleaner/', 'lastmod': '2023-03-19', 'images': []}\n", 223 | "{'loc': 'https://serpwings.com/online-seo-tools/text-processing/url-extractor/', 'lastmod': '2023-03-19', 'images': []}\n", 224 | "{'loc': 'https://serpwings.com/online-seo-tools/convertors/', 'lastmod': '2023-03-19', 'images': []}\n", 225 | "{'loc': 'https://serpwings.com/online-seo-tools/convertors/json-to-xml/', 'lastmod': '2023-03-19', 'images': []}\n", 226 | "{'loc': 'https://serpwings.com/online-seo-tools/convertors/xml-to-json/', 'lastmod': '2023-03-19', 'images': []}\n", 227 | "{'loc': 'https://serpwings.com/online-seo-tools/convertors/xml-to-tree/', 'lastmod': '2023-03-19', 'images': []}\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "smp = Sitemap(website_name=\"https://www.serpwings.com/\")\n", 233 | "smp.fetch(include_urls=True)\n", 234 | "sitemap = smp.as_dict()\n", 235 | "\n", 236 | "all_urls = sitemap['parent']['urls']\n", 237 | "for url in all_urls:\n", 238 | " # print (extract_keywrod(url['loc']))\n", 239 | " print (url)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "id": "2df4ea74-3de4-4a23-959a-2b0e57912ce5", 245 | "metadata": {}, 246 | "source": [ 247 | "## How to Plan Your Python Project\n", 248 | "\n", 249 | "So, you have written small scripts or functions and now wondering how to distbruted it to your ppers. As you write your python code and your code base grows, then it becomes cumbersome to handle them. \n", 250 | "\n", 251 | "In almost all cases, it is desired that Python code should be able to reproduce their results. However, this become difficut for data science porjects and data is udually not well planed as part of Python Packages (most developers only care of Python source code).\n", 252 | "\n", 253 | "For you project, you have different options avaiable\n", 254 | "\n", 255 | "- for small scripts inside your organizatoin, you can distribute them as it is (either .py file or notebooks)\n", 256 | "- For codes performing bunch of tasks and distrbution to broarder audiance (both in your organizations or external world, you can create python packages\n", 257 | " - Organize them as src module\n", 258 | " - organize them as script module\n", 259 | "- Use cookie cutters to organiz your projects (python code and data) for data science projects\n", 260 | "- For most of the cause where you have simple scipts then orgnaiiung htem inside bunch of jupyter note books will also work well." 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "id": "856dc6b0-c059-4d65-9f81-4811e8422373", 267 | "metadata": {}, 268 | "outputs": [], 269 | "source": [] 270 | } 271 | ], 272 | "metadata": { 273 | "kernelspec": { 274 | "display_name": "Python 3 (ipykernel)", 275 | "language": "python", 276 | "name": "python3" 277 | }, 278 | "language_info": { 279 | "codemirror_mode": { 280 | "name": "ipython", 281 | "version": 3 282 | }, 283 | "file_extension": ".py", 284 | "mimetype": "text/x-python", 285 | "name": "python", 286 | "nbconvert_exporter": "python", 287 | "pygments_lexer": "ipython3", 288 | "version": "3.10.11" 289 | } 290 | }, 291 | "nbformat": 4, 292 | "nbformat_minor": 5 293 | } 294 | -------------------------------------------------------------------------------- /02-2-introduction-to-python-digital-marketers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "97e0b61d-1c3a-4585-ba29-e8635c5ddd8c", 6 | "metadata": {}, 7 | "source": [ 8 | "# Getting Started With Python" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "d5fc2f0f-2560-4c8d-b5ba-d045e7bf0208", 14 | "metadata": {}, 15 | "source": [ 16 | "## What is REPL\n", 17 | "\n", 18 | "**REPL** is an acronym for READ, EVALUATE, PRINT and LOOP. This term is commonly used for interpreted computer programming languages e.g. Python, MATLAB, and R. " 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "id": "a44d0059-5f92-4fcd-995d-96a3fccfbac0", 24 | "metadata": {}, 25 | "source": [ 26 | "### Read \n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "id": "f9f3be8c-478d-416f-aa40-928787980fbb", 32 | "metadata": {}, 33 | "source": [ 34 | "### Evaluate\n", 35 | "- Bracket\n", 36 | "- Division\n", 37 | "- Multiplication\n", 38 | "- Plus\n", 39 | "- Minus\n", 40 | "- strings\n", 41 | "- functions" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 1, 47 | "id": "5d5cf56f-7964-4c43-9c90-b5513fa18ad4", 48 | "metadata": { 49 | "tags": [] 50 | }, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/plain": [ 55 | "4" 56 | ] 57 | }, 58 | "execution_count": 1, 59 | "metadata": {}, 60 | "output_type": "execute_result" 61 | } 62 | ], 63 | "source": [ 64 | "2+2" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 130, 70 | "id": "a268aa26-3829-41f2-8f47-7a138ddb5dbe", 71 | "metadata": { 72 | "tags": [] 73 | }, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "62.25" 79 | ] 80 | }, 81 | "execution_count": 130, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "6*10+9/4" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "id": "0122d209-c8dc-4c6a-af09-23c6095defd0", 94 | "metadata": { 95 | "tags": [] 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "%history" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "id": "03dd7736-f465-4a98-860c-0631e337fd09", 105 | "metadata": {}, 106 | "source": [ 107 | "### Print" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "id": "943b0650-53e3-456a-acc2-1ba8a157773c", 113 | "metadata": {}, 114 | "source": [ 115 | "### Loop" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "id": "332b3cfb-2e54-4aee-ba0f-f8430a5cd6b2", 121 | "metadata": {}, 122 | "source": [ 123 | "## What are Variables?\n", 124 | "\n", 125 | "3 things are associated\n", 126 | "\n", 127 | "- Name\n", 128 | "- Memory Address\n", 129 | "- Values" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 2, 135 | "id": "3a41c994-417a-4458-b5da-184e27b6d7f8", 136 | "metadata": { 137 | "tags": [] 138 | }, 139 | "outputs": [], 140 | "source": [ 141 | "ctr = 4.8\n", 142 | "number_of_visitors = 100000" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 3, 148 | "id": "7934c868-0f78-4f14-9278-c9b9da3cd527", 149 | "metadata": { 150 | "tags": [] 151 | }, 152 | "outputs": [], 153 | "source": [ 154 | "website_adress = \"https://seowings.org\"\n", 155 | "email_address = \"email@seowings.org\"" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 4, 161 | "id": "9803780c-224b-498a-9d4b-ebaa11afb1f5", 162 | "metadata": { 163 | "tags": [] 164 | }, 165 | "outputs": [ 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "4.05\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "ctr_seowings = 4.2 \n", 176 | "ctr_serowings = 3.9\n", 177 | "avg_ctr = (ctr_seowings + ctr_serowings)/2\n", 178 | "print (avg_ctr)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "id": "42510a0d-e1d7-4ad7-98cc-ec5815c95c45", 184 | "metadata": { 185 | "tags": [] 186 | }, 187 | "source": [ 188 | "## Data Types and Container" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "id": "980f470a-852f-4540-9f08-5b603810a5f0", 194 | "metadata": {}, 195 | "source": [ 196 | "### Numbers\n", 197 | "Python offers variety of numeric values for different types of operations in as easiliy as possible. " 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 5, 203 | "id": "ee0a3293-22fb-4b79-983f-f836ba0025c3", 204 | "metadata": { 205 | "tags": [] 206 | }, 207 | "outputs": [ 208 | { 209 | "data": { 210 | "text/plain": [ 211 | "5" 212 | ] 213 | }, 214 | "execution_count": 5, 215 | "metadata": {}, 216 | "output_type": "execute_result" 217 | } 218 | ], 219 | "source": [ 220 | "2+3" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 6, 226 | "id": "49062beb-6ee8-438f-95ef-b777e4d06439", 227 | "metadata": { 228 | "tags": [] 229 | }, 230 | "outputs": [ 231 | { 232 | "data": { 233 | "text/plain": [ 234 | "1.6666666666666667" 235 | ] 236 | }, 237 | "execution_count": 6, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "((2+3)/6)*2" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 7, 249 | "id": "9bcf189f-3fba-4cb8-9d5a-804ededf8363", 250 | "metadata": { 251 | "tags": [] 252 | }, 253 | "outputs": [], 254 | "source": [ 255 | "total_impressions = 45000" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 8, 261 | "id": "f0ba1b85-e664-4539-a076-52f4fb348ef7", 262 | "metadata": { 263 | "tags": [] 264 | }, 265 | "outputs": [], 266 | "source": [ 267 | "seo_volatality = 0.9" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "id": "e7f2c8f0-25d1-42f5-bcdd-fbf83362b34f", 273 | "metadata": {}, 274 | "source": [ 275 | "### Boolean\n", 276 | "\n", 277 | "True or False\n", 278 | "\n", 279 | "- Website up/down \n", 280 | " - True/False \n", 281 | " - Yes or No [String]\n", 282 | " - Updite /Response Time /count of website down(not available) [Numerical Values]\n", 283 | "- Conversion was sucessful or not\n", 284 | "- email address is valid?" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 9, 290 | "id": "20f815ba-d608-42d2-97d1-943c58c9a0b3", 291 | "metadata": { 292 | "tags": [] 293 | }, 294 | "outputs": [], 295 | "source": [ 296 | "is_website_up = False\n", 297 | "user_buy_product = True" 298 | ] 299 | }, 300 | { 301 | "cell_type": "markdown", 302 | "id": "fb973ddc-a8f0-47ef-9ad6-539302cd817d", 303 | "metadata": { 304 | "tags": [] 305 | }, 306 | "source": [ 307 | "### Dates and data" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": null, 313 | "id": "30f163aa-911e-4f78-98ca-e60a28837e4b", 314 | "metadata": { 315 | "tags": [] 316 | }, 317 | "outputs": [], 318 | "source": [ 319 | "import datetime\n", 320 | "datetime.date.fromisoformat" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": null, 326 | "id": "84f32c5d-a33d-459b-b94d-4eb5c65f773a", 327 | "metadata": { 328 | "tags": [] 329 | }, 330 | "outputs": [], 331 | "source": [ 332 | "from datetime import date\n", 333 | "\n", 334 | "# international statndard organization\n", 335 | "\n", 336 | "my_date = date.fromisoformat(\"2010-12-10\")" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": null, 342 | "id": "999f4955-7b97-4e30-9d3c-db2bc8db91a9", 343 | "metadata": { 344 | "tags": [] 345 | }, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "10" 351 | ] 352 | }, 353 | "execution_count": 3, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "my_date.day" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": null, 365 | "id": "067f3b01-7038-40a2-a3a0-5ec01ca885e1", 366 | "metadata": { 367 | "tags": [] 368 | }, 369 | "outputs": [], 370 | "source": [ 371 | "stackoverflow_archive_date = date.fromisoformat(\"2004-02-03\")" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": null, 377 | "id": "fa0eecd4-78a4-4647-8389-84cf61e8543f", 378 | "metadata": { 379 | "tags": [] 380 | }, 381 | "outputs": [ 382 | { 383 | "data": { 384 | "text/plain": [ 385 | "2" 386 | ] 387 | }, 388 | "execution_count": 6, 389 | "metadata": {}, 390 | "output_type": "execute_result" 391 | } 392 | ], 393 | "source": [ 394 | "stackoverflow_archive_date.month" 395 | ] 396 | }, 397 | { 398 | "cell_type": "code", 399 | "execution_count": null, 400 | "id": "9556cb6e-6e2a-4dea-944a-0a145ab072d8", 401 | "metadata": {}, 402 | "outputs": [], 403 | "source": [] 404 | }, 405 | { 406 | "cell_type": "code", 407 | "execution_count": null, 408 | "id": "b6df9d1d-7cdf-4999-974a-c30846e4d673", 409 | "metadata": { 410 | "tags": [] 411 | }, 412 | "outputs": [], 413 | "source": [ 414 | "from datetime import datetime" 415 | ] 416 | }, 417 | { 418 | "cell_type": "markdown", 419 | "id": "58507cef-8ba4-4504-a886-42e9f64c6db2", 420 | "metadata": { 421 | "tags": [] 422 | }, 423 | "source": [ 424 | "https://docs.python.org/3/library/datetime.html" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "id": "45a8f734-4b61-4575-b0e9-1ec6b1976dd9", 431 | "metadata": { 432 | "tags": [] 433 | }, 434 | "outputs": [], 435 | "source": [ 436 | "current_time = datetime.now()" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": null, 442 | "id": "d3b1df29-c9ac-4fb6-bfe1-4cf4f2b8d05b", 443 | "metadata": { 444 | "tags": [] 445 | }, 446 | "outputs": [ 447 | { 448 | "data": { 449 | "text/plain": [ 450 | "2023" 451 | ] 452 | }, 453 | "execution_count": 24, 454 | "metadata": {}, 455 | "output_type": "execute_result" 456 | } 457 | ], 458 | "source": [ 459 | "current_time.year" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": null, 465 | "id": "855ec95b-1d84-440f-9e15-da45f94a4d71", 466 | "metadata": { 467 | "tags": [] 468 | }, 469 | "outputs": [ 470 | { 471 | "data": { 472 | "text/plain": [ 473 | "datetime.datetime(2011, 11, 4, 0, 5, 23)" 474 | ] 475 | }, 476 | "execution_count": 26, 477 | "metadata": {}, 478 | "output_type": "execute_result" 479 | } 480 | ], 481 | "source": [ 482 | "from datetime import datetime\n", 483 | "datetime.fromisoformat('2011-11-04T00:05:23')" 484 | ] 485 | }, 486 | { 487 | "cell_type": "code", 488 | "execution_count": null, 489 | "id": "7fa42c2e-a657-4a91-b9ba-213c1deea9f6", 490 | "metadata": { 491 | "tags": [] 492 | }, 493 | "outputs": [ 494 | { 495 | "data": { 496 | "text/plain": [ 497 | "datetime.datetime(2023, 5, 24, 19, 19, 15, 938602)" 498 | ] 499 | }, 500 | "execution_count": 27, 501 | "metadata": {}, 502 | "output_type": "execute_result" 503 | } 504 | ], 505 | "source": [ 506 | "current_time" 507 | ] 508 | }, 509 | { 510 | "cell_type": "code", 511 | "execution_count": null, 512 | "id": "9720a860-e79e-411b-b98a-df810f4011ad", 513 | "metadata": { 514 | "tags": [] 515 | }, 516 | "outputs": [ 517 | { 518 | "data": { 519 | "text/plain": [ 520 | "2023" 521 | ] 522 | }, 523 | "execution_count": 28, 524 | "metadata": {}, 525 | "output_type": "execute_result" 526 | } 527 | ], 528 | "source": [ 529 | "current_time.year" 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": null, 535 | "id": "42080611-1c28-4d13-8fe9-210a6effb7bb", 536 | "metadata": { 537 | "tags": [] 538 | }, 539 | "outputs": [ 540 | { 541 | "data": { 542 | "text/plain": [ 543 | "'2023 year 05 and day is 24 19:19:15 and week 21'" 544 | ] 545 | }, 546 | "execution_count": 39, 547 | "metadata": {}, 548 | "output_type": "execute_result" 549 | } 550 | ], 551 | "source": [ 552 | "current_time.strftime(\"%Y year %m and day is %d %H:%M:%S and week %W\")" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": null, 558 | "id": "840edcd4-29aa-45ce-824f-60830ca6a868", 559 | "metadata": { 560 | "tags": [] 561 | }, 562 | "outputs": [], 563 | "source": [ 564 | "from datetime import date" 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": null, 570 | "id": "cc2663b5-dc2f-4706-ae1b-fe0aab1c5eef", 571 | "metadata": { 572 | "jupyter": { 573 | "source_hidden": true 574 | }, 575 | "tags": [] 576 | }, 577 | "outputs": [], 578 | "source": [ 579 | "dir(date)" 580 | ] 581 | }, 582 | { 583 | "cell_type": "markdown", 584 | "id": "bf8b01ac-2d1f-4d9b-a617-d65760440aca", 585 | "metadata": {}, 586 | "source": [ 587 | "### Mutable Data Types" 588 | ] 589 | }, 590 | { 591 | "cell_type": "markdown", 592 | "id": "25e491da-f19a-4fa0-afb8-46e3e80f672e", 593 | "metadata": {}, 594 | "source": [ 595 | "#### Lists" 596 | ] 597 | }, 598 | { 599 | "cell_type": "code", 600 | "execution_count": 11, 601 | "id": "5e09fcfa-0704-427f-8ed3-6356acd40bc5", 602 | "metadata": { 603 | "tags": [] 604 | }, 605 | "outputs": [ 606 | { 607 | "name": "stdout", 608 | "output_type": "stream", 609 | "text": [ 610 | "[3.2, 3.4, 5.6]\n" 611 | ] 612 | } 613 | ], 614 | "source": [ 615 | "ctr = [1.2, 3.4, 5.6]\n", 616 | "ctr[0] = 3.2\n", 617 | "\n", 618 | "print (ctr)" 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "execution_count": 12, 624 | "id": "df43cfd9-9c93-4692-8704-395cd3a6b688", 625 | "metadata": { 626 | "tags": [] 627 | }, 628 | "outputs": [ 629 | { 630 | "name": "stdout", 631 | "output_type": "stream", 632 | "text": [ 633 | "['google.com', 'yahoo.com', 'github.com', 'airbnb.com']\n" 634 | ] 635 | } 636 | ], 637 | "source": [ 638 | "list_of_websites = [\"google.com\", \"yahoo.com\", \"github.com\", \"airbnb.com\"]\n", 639 | "print (list_of_websites)" 640 | ] 641 | }, 642 | { 643 | "cell_type": "code", 644 | "execution_count": 14, 645 | "id": "7ed6d475-8d0c-432c-b070-2451d794a4f9", 646 | "metadata": { 647 | "tags": [] 648 | }, 649 | "outputs": [ 650 | { 651 | "name": "stdout", 652 | "output_type": "stream", 653 | "text": [ 654 | "['google.com', 'yahoo.com', 'github.com', 'airbnb.com', 'web.de', 'wordpress.com', 'wordpress.org']\n" 655 | ] 656 | } 657 | ], 658 | "source": [ 659 | "list_of_competitors = [\"web.de\", \"wordpress.com\", \"wordpress.org\"]\n", 660 | "new_list = list_of_websites + list_of_competitors\n", 661 | "print (new_list)" 662 | ] 663 | }, 664 | { 665 | "cell_type": "markdown", 666 | "id": "74cf9f8c-2d86-45b5-8510-e8b91abd6d96", 667 | "metadata": { 668 | "tags": [] 669 | }, 670 | "source": [ 671 | "#### Dictionaries" 672 | ] 673 | }, 674 | { 675 | "cell_type": "code", 676 | "execution_count": 15, 677 | "id": "62a5c0a6-635b-4974-9fad-b487703fb105", 678 | "metadata": { 679 | "tags": [] 680 | }, 681 | "outputs": [], 682 | "source": [ 683 | "countries = {\n", 684 | " \"Pakistan\": \"Is country on South Asia.\",\n", 685 | " \"Germany\": \"Is a Coutnry in Central Europe\"\n", 686 | "}" 687 | ] 688 | }, 689 | { 690 | "cell_type": "code", 691 | "execution_count": 17, 692 | "id": "36edfa03-f2e8-4fe8-954f-7c674365bfa0", 693 | "metadata": { 694 | "tags": [] 695 | }, 696 | "outputs": [ 697 | { 698 | "data": { 699 | "text/plain": [ 700 | "dict_keys(['Pakistan', 'Germany'])" 701 | ] 702 | }, 703 | "execution_count": 17, 704 | "metadata": {}, 705 | "output_type": "execute_result" 706 | } 707 | ], 708 | "source": [ 709 | "countries.keys()" 710 | ] 711 | }, 712 | { 713 | "cell_type": "code", 714 | "execution_count": 18, 715 | "id": "5617fa3b-0fae-4fbe-a5a5-b79883b5bc0e", 716 | "metadata": { 717 | "tags": [] 718 | }, 719 | "outputs": [ 720 | { 721 | "data": { 722 | "text/plain": [ 723 | "dict_values(['Is country on South Asia.', 'Is a Coutnry in Central Europe'])" 724 | ] 725 | }, 726 | "execution_count": 18, 727 | "metadata": {}, 728 | "output_type": "execute_result" 729 | } 730 | ], 731 | "source": [ 732 | "countries.values()" 733 | ] 734 | }, 735 | { 736 | "cell_type": "code", 737 | "execution_count": 20, 738 | "id": "2a286377-3ee4-4c13-a78a-0821e0c13ec1", 739 | "metadata": { 740 | "tags": [] 741 | }, 742 | "outputs": [ 743 | { 744 | "name": "stdout", 745 | "output_type": "stream", 746 | "text": [ 747 | "{'seowings.org': {'ctr': 3.9, 'total_visitors': 1000}}\n" 748 | ] 749 | } 750 | ], 751 | "source": [ 752 | "websites = {\n", 753 | " \"seowings.org\": {\n", 754 | " \"ctr\": 3.9, \n", 755 | " \"total_visitors\": 1000,\n", 756 | " \"total_pages\": 5,\n", 757 | " \"owner: \"Faisal Shahzad\"\n", 758 | " }, \n", 759 | " \"jang.com.pk\": {\n", 760 | " \"ctr\": 3.9, \n", 761 | " \"total_visitors\": 1000,\n", 762 | " \"total_pages\": 5,\n", 763 | " \"owner: \"Jang Media\"\n", 764 | " }\n", 765 | "}\n", 766 | "\n", 767 | "print (websites)" 768 | ] 769 | }, 770 | { 771 | "cell_type": "markdown", 772 | "id": "18afb1b2-98af-4036-a37f-a3f6278f8412", 773 | "metadata": {}, 774 | "source": [ 775 | "#### Sets" 776 | ] 777 | }, 778 | { 779 | "cell_type": "code", 780 | "execution_count": 21, 781 | "id": "79bd5b8a-b135-44ba-92a6-014562a3dead", 782 | "metadata": { 783 | "tags": [] 784 | }, 785 | "outputs": [ 786 | { 787 | "data": { 788 | "text/plain": [ 789 | "{'Gujranwala', 'Lahore', 'Okara'}" 790 | ] 791 | }, 792 | "execution_count": 21, 793 | "metadata": {}, 794 | "output_type": "execute_result" 795 | } 796 | ], 797 | "source": [ 798 | "set_of_cities = {\"Lahore\", \"Gujranwala\",\"Okara\"}\n", 799 | "set_of_cities" 800 | ] 801 | }, 802 | { 803 | "cell_type": "code", 804 | "execution_count": 22, 805 | "id": "beb37552-0cb8-48b7-9a52-90232014b4a7", 806 | "metadata": { 807 | "tags": [] 808 | }, 809 | "outputs": [ 810 | { 811 | "data": { 812 | "text/plain": [ 813 | "['website1.com', 'website2.com', 'website3.com', 'website2.com']" 814 | ] 815 | }, 816 | "execution_count": 22, 817 | "metadata": {}, 818 | "output_type": "execute_result" 819 | } 820 | ], 821 | "source": [ 822 | "websites = [\"website1.com\", \"website2.com\", \"website3.com\", \"website2.com\"]\n", 823 | "\n", 824 | "websites" 825 | ] 826 | }, 827 | { 828 | "cell_type": "code", 829 | "execution_count": 24, 830 | "id": "45d43db3-e240-4566-a689-2e2c51e45c64", 831 | "metadata": { 832 | "tags": [] 833 | }, 834 | "outputs": [ 835 | { 836 | "data": { 837 | "text/plain": [ 838 | "{'website1.com', 'website2.com', 'website3.com'}" 839 | ] 840 | }, 841 | "execution_count": 24, 842 | "metadata": {}, 843 | "output_type": "execute_result" 844 | } 845 | ], 846 | "source": [ 847 | "unique_websits = set(websites)\n", 848 | "unique_websits" 849 | ] 850 | }, 851 | { 852 | "cell_type": "markdown", 853 | "id": "0bb7d42e-94d5-4fbf-bd2c-1f06a499f5cc", 854 | "metadata": {}, 855 | "source": [ 856 | "list(unique_websits)" 857 | ] 858 | }, 859 | { 860 | "cell_type": "code", 861 | "execution_count": 148, 862 | "id": "6d5dac88-bf4d-4532-9a6e-2932a09257b2", 863 | "metadata": { 864 | "tags": [] 865 | }, 866 | "outputs": [], 867 | "source": [ 868 | "competitor_set_1 = {\"website1.com\", \"website2.com\"}\n", 869 | "competitor_set_2 = {\"website3.com\", \"website4.com\"}" 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": 149, 875 | "id": "ec7e3e4b-9747-4671-a4cf-95c41515f040", 876 | "metadata": { 877 | "tags": [] 878 | }, 879 | "outputs": [ 880 | { 881 | "name": "stdout", 882 | "output_type": "stream", 883 | "text": [ 884 | "{'website1.com', 'website2.com'}\n", 885 | "{'website4.com', 'website3.com'}\n" 886 | ] 887 | } 888 | ], 889 | "source": [ 890 | "print (competitor_set_1)\n", 891 | "print (competitor_set_2)" 892 | ] 893 | }, 894 | { 895 | "cell_type": "code", 896 | "execution_count": 150, 897 | "id": "01895817-5e7d-4459-a384-d9d0788c8c9e", 898 | "metadata": { 899 | "tags": [] 900 | }, 901 | "outputs": [ 902 | { 903 | "data": { 904 | "text/plain": [ 905 | "{'website1.com', 'website2.com', 'website3.com', 'website4.com'}" 906 | ] 907 | }, 908 | "execution_count": 150, 909 | "metadata": {}, 910 | "output_type": "execute_result" 911 | } 912 | ], 913 | "source": [ 914 | "competitor_set_1 | competitor_set_2" 915 | ] 916 | }, 917 | { 918 | "cell_type": "markdown", 919 | "id": "d932998b-bbc2-4a24-b955-274a68478b5a", 920 | "metadata": {}, 921 | "source": [ 922 | "### Immutable Data Types" 923 | ] 924 | }, 925 | { 926 | "cell_type": "markdown", 927 | "id": "00c88500-03b0-43f6-b3be-b19723c61ed8", 928 | "metadata": {}, 929 | "source": [ 930 | "#### Strings \n", 931 | "To dispaly charters/output to the user. For most part of computer and their programming, this is main mode of communcation with machines and humans. In future chapters, we will discuss other modes of communcation in in more details." 932 | ] 933 | }, 934 | { 935 | "cell_type": "code", 936 | "execution_count": 29, 937 | "id": "ed4408e3-801b-422b-8124-271484600089", 938 | "metadata": { 939 | "tags": [] 940 | }, 941 | "outputs": [ 942 | { 943 | "name": "stdout", 944 | "output_type": "stream", 945 | "text": [ 946 | "r\n" 947 | ] 948 | } 949 | ], 950 | "source": [ 951 | "city = \"Lahore\"\n", 952 | "website = \"jang.com.pk\"\n", 953 | "\n", 954 | "print (city[-2])" 955 | ] 956 | }, 957 | { 958 | "cell_type": "code", 959 | "execution_count": 31, 960 | "id": "5f126e24-7bad-4d2c-89da-a8fbf8c892bf", 961 | "metadata": { 962 | "tags": [] 963 | }, 964 | "outputs": [ 965 | { 966 | "ename": "TypeError", 967 | "evalue": "'str' object does not support item assignment", 968 | "output_type": "error", 969 | "traceback": [ 970 | "\u001b[1;31m--------------------------------------------------------\u001b[0m", 971 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 972 | "Cell \u001b[1;32mIn[31], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mcity\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mD\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", 973 | "\u001b[1;31mTypeError\u001b[0m: 'str' object does not support item assignment" 974 | ] 975 | } 976 | ], 977 | "source": [ 978 | "city[0] = \"D\"" 979 | ] 980 | }, 981 | { 982 | "cell_type": "markdown", 983 | "id": "0c8af836-27ad-4c96-ac51-7f81fe6167d6", 984 | "metadata": {}, 985 | "source": [ 986 | "##### Strings With Single Quotes" 987 | ] 988 | }, 989 | { 990 | "cell_type": "code", 991 | "execution_count": 34, 992 | "id": "cce993a7-9068-4aaf-84ce-1464bb33a2fc", 993 | "metadata": { 994 | "tags": [] 995 | }, 996 | "outputs": [], 997 | "source": [ 998 | "city = 'Lahore'" 999 | ] 1000 | }, 1001 | { 1002 | "cell_type": "markdown", 1003 | "id": "c54d2633-639a-4869-943f-688798aae75a", 1004 | "metadata": {}, 1005 | "source": [ 1006 | "##### Strings With Double" 1007 | ] 1008 | }, 1009 | { 1010 | "cell_type": "code", 1011 | "execution_count": 35, 1012 | "id": "8c3f7410-16c3-4928-a87f-07fbf1a57cca", 1013 | "metadata": { 1014 | "tags": [] 1015 | }, 1016 | "outputs": [], 1017 | "source": [ 1018 | "city = \"Lahore\"" 1019 | ] 1020 | }, 1021 | { 1022 | "cell_type": "markdown", 1023 | "id": "9cbe8f6b-7abb-442d-97d7-e768687bf4e5", 1024 | "metadata": {}, 1025 | "source": [ 1026 | "##### Strings With Tripple" 1027 | ] 1028 | }, 1029 | { 1030 | "cell_type": "code", 1031 | "execution_count": 37, 1032 | "id": "c27b0f8f-245d-407c-af33-b90df37f25dc", 1033 | "metadata": { 1034 | "tags": [] 1035 | }, 1036 | "outputs": [ 1037 | { 1038 | "name": "stdout", 1039 | "output_type": "stream", 1040 | "text": [ 1041 | "\n", 1042 | "THis is my sample markeitng letter\n", 1043 | "THis is my sample markeitng letter\n", 1044 | "THis is my sample markeitng letter\n", 1045 | "THis is my sample markeitng letter\n", 1046 | "\n" 1047 | ] 1048 | } 1049 | ], 1050 | "source": [ 1051 | "# Comments\n", 1052 | "# docstring\n", 1053 | "\n", 1054 | "letter = \"\"\"\n", 1055 | "THis is my sample markeitng letter\n", 1056 | "THis is my sample markeitng letter\n", 1057 | "THis is my sample markeitng letter\n", 1058 | "THis is my sample markeitng letter\n", 1059 | "\"\"\"\n", 1060 | "\n", 1061 | "print (letter)" 1062 | ] 1063 | }, 1064 | { 1065 | "cell_type": "markdown", 1066 | "id": "9b9767f8-0298-4dc5-9c36-06244494f06e", 1067 | "metadata": {}, 1068 | "source": [ 1069 | "##### Uderstanding F-String" 1070 | ] 1071 | }, 1072 | { 1073 | "cell_type": "code", 1074 | "execution_count": 39, 1075 | "id": "13238460-04a1-4018-afed-61ec9300f5ee", 1076 | "metadata": { 1077 | "tags": [] 1078 | }, 1079 | "outputs": [ 1080 | { 1081 | "name": "stdout", 1082 | "output_type": "stream", 1083 | "text": [ 1084 | "Welcome to the Data Science Course\n" 1085 | ] 1086 | } 1087 | ], 1088 | "source": [ 1089 | "print (\"Welcome to the Data Science Course\")" 1090 | ] 1091 | }, 1092 | { 1093 | "cell_type": "code", 1094 | "execution_count": 40, 1095 | "id": "738c5da3-2f3b-4cbc-8f00-0a137abe582b", 1096 | "metadata": { 1097 | "tags": [] 1098 | }, 1099 | "outputs": [ 1100 | { 1101 | "name": "stdout", 1102 | "output_type": "stream", 1103 | "text": [ 1104 | "Hi Faisal! Welcome to the Data Science Course\n" 1105 | ] 1106 | } 1107 | ], 1108 | "source": [ 1109 | "print (\"Hi Faisal!\", \"Welcome to the Data Science Course\")" 1110 | ] 1111 | }, 1112 | { 1113 | "cell_type": "code", 1114 | "execution_count": 41, 1115 | "id": "15754682-826b-4789-9a09-f7ff3e2752d2", 1116 | "metadata": { 1117 | "tags": [] 1118 | }, 1119 | "outputs": [ 1120 | { 1121 | "name": "stdout", 1122 | "output_type": "stream", 1123 | "text": [ 1124 | "My website Click though rate is 4.2\n" 1125 | ] 1126 | } 1127 | ], 1128 | "source": [ 1129 | "print(\"My website Click though rate is 4.2\")" 1130 | ] 1131 | }, 1132 | { 1133 | "cell_type": "code", 1134 | "execution_count": 42, 1135 | "id": "67a30179-547f-4f71-84c0-a5a16451963b", 1136 | "metadata": { 1137 | "tags": [] 1138 | }, 1139 | "outputs": [ 1140 | { 1141 | "name": "stdout", 1142 | "output_type": "stream", 1143 | "text": [ 1144 | "My website Click though rate is 2.3\n" 1145 | ] 1146 | } 1147 | ], 1148 | "source": [ 1149 | "ctr = 2.3\n", 1150 | "print(\"My website Click though rate is \", ctr)" 1151 | ] 1152 | }, 1153 | { 1154 | "cell_type": "code", 1155 | "execution_count": 161, 1156 | "id": "adcb3b39-df45-400c-8647-940bc0850968", 1157 | "metadata": { 1158 | "tags": [] 1159 | }, 1160 | "outputs": [ 1161 | { 1162 | "name": "stdout", 1163 | "output_type": "stream", 1164 | "text": [ 1165 | "This is my text for 1.2\n" 1166 | ] 1167 | } 1168 | ], 1169 | "source": [ 1170 | "print (f\"This is my text for {ctr}\")" 1171 | ] 1172 | }, 1173 | { 1174 | "cell_type": "code", 1175 | "execution_count": 158, 1176 | "id": "4d26c3ff-8efd-4317-a2d1-f58ec46573a9", 1177 | "metadata": { 1178 | "tags": [] 1179 | }, 1180 | "outputs": [ 1181 | { 1182 | "name": "stdout", 1183 | "output_type": "stream", 1184 | "text": [ 1185 | "My website https://serpwings.com Click though rate is 1.2\n" 1186 | ] 1187 | } 1188 | ], 1189 | "source": [ 1190 | "ctr = 1.2\n", 1191 | "website = \"https://serpwings.com\"\n", 1192 | "\n", 1193 | "print(f\"My website {website} Click though rate is {ctr}\")" 1194 | ] 1195 | }, 1196 | { 1197 | "cell_type": "code", 1198 | "execution_count": 44, 1199 | "id": "5557f261-1cb0-4dad-b734-c6ebb4bd9472", 1200 | "metadata": { 1201 | "tags": [] 1202 | }, 1203 | "outputs": [ 1204 | { 1205 | "name": "stdout", 1206 | "output_type": "stream", 1207 | "text": [ 1208 | "You are my content writer for the website laptopforkids.com. You should create an outline for a blog post on Best Laptops for Kids. Please write it for kids of age 10 and do not exceed 35 words \n" 1209 | ] 1210 | } 1211 | ], 1212 | "source": [ 1213 | "my_website = \"laptopforkids.com\"\n", 1214 | "blog_post_title = \"Best Laptops for Kids\"\n", 1215 | "word_limit = 35\n", 1216 | "\n", 1217 | "print (f\"You are my content writer for the website {my_website}. You should create an outline for a blog post on {blog_post_title}. Please write it for kids of age 10 and do not exceed {word_limit} words \")" 1218 | ] 1219 | }, 1220 | { 1221 | "cell_type": "code", 1222 | "execution_count": 45, 1223 | "id": "dddf62db-37c1-402d-b77f-b07cb932d05e", 1224 | "metadata": { 1225 | "tags": [] 1226 | }, 1227 | "outputs": [ 1228 | { 1229 | "name": "stdout", 1230 | "output_type": "stream", 1231 | "text": [ 1232 | "This is my titleWelcome to my website on Digital Marketing!\n" 1233 | ] 1234 | } 1235 | ], 1236 | "source": [ 1237 | "title = \"This is my title\"\n", 1238 | "content = \"Welcome to my website on Digital Marketing!\"\n", 1239 | "generator = f\"{title}{content}\"\n", 1240 | "\n", 1241 | "# Javascirpt, # CSS \n", 1242 | "\n", 1243 | "print(generator)" 1244 | ] 1245 | }, 1246 | { 1247 | "cell_type": "markdown", 1248 | "id": "733b395b-a5bd-4855-9e4b-ace20bd2eb3b", 1249 | "metadata": {}, 1250 | "source": [ 1251 | "#### Tuples" 1252 | ] 1253 | }, 1254 | { 1255 | "cell_type": "code", 1256 | "execution_count": 162, 1257 | "id": "bf4f0417-09f7-459f-9e4a-13b9650a47c7", 1258 | "metadata": { 1259 | "tags": [] 1260 | }, 1261 | "outputs": [ 1262 | { 1263 | "data": { 1264 | "text/plain": [ 1265 | "(4, 6)" 1266 | ] 1267 | }, 1268 | "execution_count": 162, 1269 | "metadata": {}, 1270 | "output_type": "execute_result" 1271 | } 1272 | ], 1273 | "source": [ 1274 | "(4, 6)" 1275 | ] 1276 | }, 1277 | { 1278 | "cell_type": "code", 1279 | "execution_count": 46, 1280 | "id": "eea110ed-125f-473d-8b0b-04be4df53ad9", 1281 | "metadata": { 1282 | "tags": [] 1283 | }, 1284 | "outputs": [], 1285 | "source": [ 1286 | "a = (4, 5)" 1287 | ] 1288 | }, 1289 | { 1290 | "cell_type": "code", 1291 | "execution_count": 48, 1292 | "id": "6607b971-d3cd-498d-9c96-8833800e56ee", 1293 | "metadata": { 1294 | "tags": [] 1295 | }, 1296 | "outputs": [ 1297 | { 1298 | "data": { 1299 | "text/plain": [ 1300 | "5" 1301 | ] 1302 | }, 1303 | "execution_count": 48, 1304 | "metadata": {}, 1305 | "output_type": "execute_result" 1306 | } 1307 | ], 1308 | "source": [ 1309 | "a[1]" 1310 | ] 1311 | }, 1312 | { 1313 | "cell_type": "code", 1314 | "execution_count": 165, 1315 | "id": "e09a7ebe-7eaa-4f02-9a3c-a65884ebfce6", 1316 | "metadata": { 1317 | "tags": [] 1318 | }, 1319 | "outputs": [ 1320 | { 1321 | "data": { 1322 | "text/plain": [ 1323 | "('jang.com.pk', 100000)" 1324 | ] 1325 | }, 1326 | "execution_count": 165, 1327 | "metadata": {}, 1328 | "output_type": "execute_result" 1329 | } 1330 | ], 1331 | "source": [ 1332 | "website = (\"jang.com.pk\", 100000)\n", 1333 | "website" 1334 | ] 1335 | }, 1336 | { 1337 | "cell_type": "code", 1338 | "execution_count": 166, 1339 | "id": "f59da557-38a1-4073-a3c8-7d59fb25dd06", 1340 | "metadata": { 1341 | "tags": [] 1342 | }, 1343 | "outputs": [], 1344 | "source": [ 1345 | "#tuple unpacking\n", 1346 | "website_name, number_of_visitors = website" 1347 | ] 1348 | }, 1349 | { 1350 | "cell_type": "code", 1351 | "execution_count": 167, 1352 | "id": "265543cb-f3a7-4606-97a2-f90ec67e46a6", 1353 | "metadata": { 1354 | "tags": [] 1355 | }, 1356 | "outputs": [ 1357 | { 1358 | "data": { 1359 | "text/plain": [ 1360 | "'jang.com.pk'" 1361 | ] 1362 | }, 1363 | "execution_count": 167, 1364 | "metadata": {}, 1365 | "output_type": "execute_result" 1366 | } 1367 | ], 1368 | "source": [ 1369 | "website_name" 1370 | ] 1371 | }, 1372 | { 1373 | "cell_type": "code", 1374 | "execution_count": 168, 1375 | "id": "8c3fdb88-388c-47fd-9e0f-acb5c3f5f3a8", 1376 | "metadata": { 1377 | "tags": [] 1378 | }, 1379 | "outputs": [ 1380 | { 1381 | "data": { 1382 | "text/plain": [ 1383 | "100000" 1384 | ] 1385 | }, 1386 | "execution_count": 168, 1387 | "metadata": {}, 1388 | "output_type": "execute_result" 1389 | } 1390 | ], 1391 | "source": [ 1392 | "number_of_visitors" 1393 | ] 1394 | }, 1395 | { 1396 | "cell_type": "code", 1397 | "execution_count": 169, 1398 | "id": "22019095-ae45-46e8-b570-6e57842801e0", 1399 | "metadata": { 1400 | "tags": [] 1401 | }, 1402 | "outputs": [ 1403 | { 1404 | "data": { 1405 | "text/plain": [ 1406 | "('https://www.seowings.org/static-wordpress/', '2022-11-18')" 1407 | ] 1408 | }, 1409 | "execution_count": 169, 1410 | "metadata": {}, 1411 | "output_type": "execute_result" 1412 | } 1413 | ], 1414 | "source": [ 1415 | "sitemap = (\"https://www.seowings.org/static-wordpress/\", \"2022-11-18\")\n", 1416 | "sitemap" 1417 | ] 1418 | }, 1419 | { 1420 | "cell_type": "code", 1421 | "execution_count": 170, 1422 | "id": "cc35b81c-91e3-4363-8955-8c58430a2a1f", 1423 | "metadata": { 1424 | "tags": [] 1425 | }, 1426 | "outputs": [ 1427 | { 1428 | "data": { 1429 | "text/plain": [ 1430 | "('https://www.seowings.org/static-wordpress/', '2022-11-18', 0.7)" 1431 | ] 1432 | }, 1433 | "execution_count": 170, 1434 | "metadata": {}, 1435 | "output_type": "execute_result" 1436 | } 1437 | ], 1438 | "source": [ 1439 | "page_loc = (\"https://www.seowings.org/static-wordpress/\", \"2022-11-18\", 0.7)\n", 1440 | "page_loc" 1441 | ] 1442 | }, 1443 | { 1444 | "cell_type": "code", 1445 | "execution_count": 172, 1446 | "id": "9c702c88-5e15-451c-912a-722638f07009", 1447 | "metadata": { 1448 | "tags": [] 1449 | }, 1450 | "outputs": [], 1451 | "source": [ 1452 | "url, lastmod, priority = page_loc" 1453 | ] 1454 | }, 1455 | { 1456 | "cell_type": "code", 1457 | "execution_count": 173, 1458 | "id": "e31322bc-c2ab-4a4a-9f48-7787bbd43606", 1459 | "metadata": { 1460 | "tags": [] 1461 | }, 1462 | "outputs": [ 1463 | { 1464 | "data": { 1465 | "text/plain": [ 1466 | "'https://www.seowings.org/static-wordpress/'" 1467 | ] 1468 | }, 1469 | "execution_count": 173, 1470 | "metadata": {}, 1471 | "output_type": "execute_result" 1472 | } 1473 | ], 1474 | "source": [ 1475 | "url" 1476 | ] 1477 | }, 1478 | { 1479 | "cell_type": "code", 1480 | "execution_count": 174, 1481 | "id": "7ee792d6-7fac-4430-a9aa-9ce23cc7c8b5", 1482 | "metadata": { 1483 | "tags": [] 1484 | }, 1485 | "outputs": [ 1486 | { 1487 | "data": { 1488 | "text/plain": [ 1489 | "'2022-11-18'" 1490 | ] 1491 | }, 1492 | "execution_count": 174, 1493 | "metadata": {}, 1494 | "output_type": "execute_result" 1495 | } 1496 | ], 1497 | "source": [ 1498 | "lastmod" 1499 | ] 1500 | }, 1501 | { 1502 | "cell_type": "code", 1503 | "execution_count": 175, 1504 | "id": "e8fe5981-2139-416f-ac3c-9c281fa7480b", 1505 | "metadata": { 1506 | "tags": [] 1507 | }, 1508 | "outputs": [ 1509 | { 1510 | "data": { 1511 | "text/plain": [ 1512 | "0.7" 1513 | ] 1514 | }, 1515 | "execution_count": 175, 1516 | "metadata": {}, 1517 | "output_type": "execute_result" 1518 | } 1519 | ], 1520 | "source": [ 1521 | "priority" 1522 | ] 1523 | }, 1524 | { 1525 | "cell_type": "code", 1526 | "execution_count": 59, 1527 | "id": "4ea8a291-efb1-44cc-8d26-39dd0f9a00b8", 1528 | "metadata": { 1529 | "tags": [] 1530 | }, 1531 | "outputs": [ 1532 | { 1533 | "name": "stdout", 1534 | "output_type": "stream", 1535 | "text": [ 1536 | "5 9 1198\n" 1537 | ] 1538 | } 1539 | ], 1540 | "source": [ 1541 | "# Major Version\n", 1542 | "# Minor Version\n", 1543 | "# Revision \n", 1544 | "\n", 1545 | "version = \"5.9.1198\"\n", 1546 | "major, minor, revision = tuple(version.split(\".\"))\n", 1547 | "\n", 1548 | "print (major, minor, revision)" 1549 | ] 1550 | }, 1551 | { 1552 | "cell_type": "code", 1553 | "execution_count": 60, 1554 | "id": "ff3b59b6-5ae7-4c5b-978c-656bbc87fd1c", 1555 | "metadata": { 1556 | "tags": [] 1557 | }, 1558 | "outputs": [], 1559 | "source": [ 1560 | "major, minor, _ = tuple(version.split(\".\"))" 1561 | ] 1562 | }, 1563 | { 1564 | "cell_type": "markdown", 1565 | "id": "1df9f927-3b59-47d6-83bc-76469367726c", 1566 | "metadata": {}, 1567 | "source": [ 1568 | "## Conditional Statements" 1569 | ] 1570 | }, 1571 | { 1572 | "cell_type": "markdown", 1573 | "id": "619dfe62-8332-4163-84af-8c2d9d9e11d2", 1574 | "metadata": {}, 1575 | "source": [ 1576 | "### Boolean algebra\n", 1577 | "https://en.wikipedia.org/wiki/Boolean_algebra" 1578 | ] 1579 | }, 1580 | { 1581 | "cell_type": "markdown", 1582 | "id": "f23081b2-3af2-4477-a785-1538d98bd170", 1583 | "metadata": {}, 1584 | "source": [ 1585 | "### if " 1586 | ] 1587 | }, 1588 | { 1589 | "cell_type": "code", 1590 | "execution_count": 7, 1591 | "id": "d690899c-10d4-4937-8996-6c663f658d66", 1592 | "metadata": { 1593 | "tags": [] 1594 | }, 1595 | "outputs": [ 1596 | { 1597 | "name": "stdout", 1598 | "output_type": "stream", 1599 | "text": [ 1600 | "You need an SEO Expert\n" 1601 | ] 1602 | } 1603 | ], 1604 | "source": [ 1605 | "ctr = 1.3\n", 1606 | "\n", 1607 | "if ctr < 2:\n", 1608 | " print (\"You need an SEO Expert\")\n", 1609 | "\n" 1610 | ] 1611 | }, 1612 | { 1613 | "cell_type": "code", 1614 | "execution_count": null, 1615 | "id": "dee8db01-f746-42a5-a91c-81d425864f41", 1616 | "metadata": {}, 1617 | "outputs": [], 1618 | "source": [ 1619 | "wp_current_version = \"6.2.0\"\n", 1620 | "wp_competitor_version = \"5.8.0\" # web scraping\n", 1621 | "\n", 1622 | "# upacking\n", 1623 | "\n", 1624 | "if wp_competitor_version < wp_current_version:\n", 1625 | " print (\"Your competitor is not uptodate\")\n", 1626 | " " 1627 | ] 1628 | }, 1629 | { 1630 | "cell_type": "markdown", 1631 | "id": "62953fbe-5f44-4002-bf4f-1a43bef6434c", 1632 | "metadata": {}, 1633 | "source": [ 1634 | "### if else" 1635 | ] 1636 | }, 1637 | { 1638 | "cell_type": "code", 1639 | "execution_count": 9, 1640 | "id": "7a92f6c2-cd0b-45c0-84f6-e8bd4cc1637a", 1641 | "metadata": { 1642 | "tags": [] 1643 | }, 1644 | "outputs": [ 1645 | { 1646 | "name": "stdout", 1647 | "output_type": "stream", 1648 | "text": [ 1649 | "this is very low ctr\n" 1650 | ] 1651 | } 1652 | ], 1653 | "source": [ 1654 | "ctr = 1.3\n", 1655 | "\n", 1656 | "if ctr < 2: \n", 1657 | " print (\"this is very low ctr\")\n", 1658 | "else:\n", 1659 | " print (\"your ctr is good, carry on\")" 1660 | ] 1661 | }, 1662 | { 1663 | "cell_type": "markdown", 1664 | "id": "7a543762-82ad-463f-9d39-c5144ab93170", 1665 | "metadata": { 1666 | "tags": [] 1667 | }, 1668 | "source": [ 1669 | "**More Pythonic Solution**" 1670 | ] 1671 | }, 1672 | { 1673 | "cell_type": "code", 1674 | "execution_count": 10, 1675 | "id": "862cba2f-4a32-4d20-aab6-1f37c5ee555b", 1676 | "metadata": { 1677 | "tags": [] 1678 | }, 1679 | "outputs": [ 1680 | { 1681 | "name": "stdout", 1682 | "output_type": "stream", 1683 | "text": [ 1684 | "True\n" 1685 | ] 1686 | } 1687 | ], 1688 | "source": [ 1689 | "ctr = 1.3\n", 1690 | "\n", 1691 | "output = True if ctr < 3 else False\n", 1692 | "print (output)" 1693 | ] 1694 | }, 1695 | { 1696 | "cell_type": "markdown", 1697 | "id": "4279454a-e3d8-4ab0-9aa5-1044c4fc1ed8", 1698 | "metadata": {}, 1699 | "source": [ 1700 | "### if elif else" 1701 | ] 1702 | }, 1703 | { 1704 | "cell_type": "code", 1705 | "execution_count": 11, 1706 | "id": "a9d586ce-1a85-4992-b417-90691aa58b4a", 1707 | "metadata": { 1708 | "tags": [] 1709 | }, 1710 | "outputs": [ 1711 | { 1712 | "name": "stdout", 1713 | "output_type": "stream", 1714 | "text": [ 1715 | "your ctr is good, carry on\n" 1716 | ] 1717 | } 1718 | ], 1719 | "source": [ 1720 | "ctr = 4.3\n", 1721 | "\n", 1722 | "if ctr < 2: \n", 1723 | " print (\"this is very low ctr\")\n", 1724 | "elif ctr >=2 and ctr <3:\n", 1725 | " print (\"this is an average ctr\")\n", 1726 | "else:\n", 1727 | "\n", 1728 | " print (\"your ctr is good, carry on\")" 1729 | ] 1730 | }, 1731 | { 1732 | "cell_type": "markdown", 1733 | "id": "98c92fc7-9dc3-4a24-b8d9-872badccef7b", 1734 | "metadata": {}, 1735 | "source": [ 1736 | "### Switches\n", 1737 | "\n", 1738 | "PYthon do not support switches as it is withmost of the other programming languages." 1739 | ] 1740 | }, 1741 | { 1742 | "cell_type": "markdown", 1743 | "id": "8afd00e4-13a2-4d2f-b182-565322479fcc", 1744 | "metadata": {}, 1745 | "source": [ 1746 | "## Loops For Repeated Operations" 1747 | ] 1748 | }, 1749 | { 1750 | "cell_type": "code", 1751 | "execution_count": 71, 1752 | "id": "afaf9434-6948-4e89-923f-76a152faf5d8", 1753 | "metadata": { 1754 | "tags": [] 1755 | }, 1756 | "outputs": [ 1757 | { 1758 | "data": { 1759 | "text/plain": [ 1760 | "3" 1761 | ] 1762 | }, 1763 | "execution_count": 71, 1764 | "metadata": {}, 1765 | "output_type": "execute_result" 1766 | } 1767 | ], 1768 | "source": [ 1769 | "array_of_youtube_videos = [\"video1\", \"video2\", \"video3\"]\n", 1770 | "len(array_of_youtube_videos)" 1771 | ] 1772 | }, 1773 | { 1774 | "cell_type": "code", 1775 | "execution_count": 61, 1776 | "id": "fdaf3e60-74d6-4708-b4cc-ac2ef5ebe8ea", 1777 | "metadata": { 1778 | "tags": [] 1779 | }, 1780 | "outputs": [], 1781 | "source": [ 1782 | "# array of tuple\n", 1783 | "sitemap_url_set = [(\"https://www.seowings.org/static-wordpress/\", \"2022-11-18\"),\n", 1784 | " (\"https://www.seowings.org/simply-static-tutorial/\", \"2023-03-05\")]" 1785 | ] 1786 | }, 1787 | { 1788 | "cell_type": "code", 1789 | "execution_count": 62, 1790 | "id": "dfc35859-d4b3-42e2-943d-1d1a9a7d5260", 1791 | "metadata": { 1792 | "tags": [] 1793 | }, 1794 | "outputs": [ 1795 | { 1796 | "data": { 1797 | "text/plain": [ 1798 | "[('https://www.seowings.org/static-wordpress/', '2022-11-18'),\n", 1799 | " ('https://www.seowings.org/simply-static-tutorial/', '2023-03-05')]" 1800 | ] 1801 | }, 1802 | "execution_count": 62, 1803 | "metadata": {}, 1804 | "output_type": "execute_result" 1805 | } 1806 | ], 1807 | "source": [ 1808 | "sitemap_url_set" 1809 | ] 1810 | }, 1811 | { 1812 | "cell_type": "code", 1813 | "execution_count": 64, 1814 | "id": "df0003ff-1af7-417a-b1cd-bfadcf1d3269", 1815 | "metadata": { 1816 | "tags": [] 1817 | }, 1818 | "outputs": [ 1819 | { 1820 | "name": "stdout", 1821 | "output_type": "stream", 1822 | "text": [ 1823 | "https://www.seowings.org/static-wordpress/ 2022-11-18\n", 1824 | "https://www.seowings.org/simply-static-tutorial/ 2023-03-05\n" 1825 | ] 1826 | } 1827 | ], 1828 | "source": [ 1829 | "for url in sitemap_url_set:\n", 1830 | " loc, lastmod = url #unpack\n", 1831 | " print (loc, lastmod)" 1832 | ] 1833 | }, 1834 | { 1835 | "cell_type": "code", 1836 | "execution_count": 14, 1837 | "id": "430aa111-4f96-496a-966f-e38deaefb380", 1838 | "metadata": { 1839 | "tags": [] 1840 | }, 1841 | "outputs": [ 1842 | { 1843 | "name": "stdout", 1844 | "output_type": "stream", 1845 | "text": [ 1846 | "https://cheapandbesthosting.com\n", 1847 | "https://geekflare.com\n", 1848 | "https://gethugothemes.com\n", 1849 | "https://medium.com\n", 1850 | "https://saasxtra.com\n", 1851 | "https://stackshare.io\n" 1852 | ] 1853 | } 1854 | ], 1855 | "source": [ 1856 | "list_of_competitors = [\n", 1857 | " \"https://cheapandbesthosting.com\", \n", 1858 | " \"https://geekflare.com\", \n", 1859 | " \"https://gethugothemes.com\", \n", 1860 | " \"https://medium.com\", \n", 1861 | " \"https://saasxtra.com\", \n", 1862 | " \"https://stackshare.io\"\n", 1863 | "]\n", 1864 | "len(list_of_competitors)\n", 1865 | "\n", 1866 | "for competitor in list_of_competitors:\n", 1867 | " print (competitor)" 1868 | ] 1869 | }, 1870 | { 1871 | "cell_type": "code", 1872 | "execution_count": 65, 1873 | "id": "336cd268-89c4-4f76-a347-a8e5d4155085", 1874 | "metadata": { 1875 | "tags": [] 1876 | }, 1877 | "outputs": [ 1878 | { 1879 | "name": "stdout", 1880 | "output_type": "stream", 1881 | "text": [ 1882 | "not my competitor\n", 1883 | "not my competitor\n", 1884 | "wordpress.org\n" 1885 | ] 1886 | } 1887 | ], 1888 | "source": [ 1889 | "for competitor in list_of_competitors:\n", 1890 | " if competitor.endswith(\".org\"):\n", 1891 | " print (competitor)\n", 1892 | " else:\n", 1893 | " print (\"not my competitor\")" 1894 | ] 1895 | }, 1896 | { 1897 | "cell_type": "code", 1898 | "execution_count": 16, 1899 | "id": "ac9c0232-31e3-4eb5-b17f-0d42743c8422", 1900 | "metadata": { 1901 | "tags": [] 1902 | }, 1903 | "outputs": [ 1904 | { 1905 | "name": "stdout", 1906 | "output_type": "stream", 1907 | "text": [ 1908 | "https://cheapandbesthosting.com not an org domain\n", 1909 | "https://geekflare.com not an org domain\n", 1910 | "https://gethugothemes.com not an org domain\n", 1911 | "https://medium.com not an org domain\n", 1912 | "https://saasxtra.com not an org domain\n", 1913 | "https://stackshare.io not an org domain\n", 1914 | "6\n" 1915 | ] 1916 | } 1917 | ], 1918 | "source": [ 1919 | "for competitor in list_of_competitors:\n", 1920 | " if competitor.endswith(\".org\"):\n", 1921 | " print (competitor, \"this is Non Profit Org dmain\")\n", 1922 | " elif competitor.endswith(\".de\"):\n", 1923 | " print (competitor, \"this is German dmain\")\n", 1924 | " else:\n", 1925 | " print (competitor, \"not an org domain\")\n", 1926 | "\n", 1927 | "total_competitors = len(list_of_competitors)\n", 1928 | "print (total_competitors)" 1929 | ] 1930 | }, 1931 | { 1932 | "cell_type": "code", 1933 | "execution_count": 17, 1934 | "id": "58cab14a-9016-425b-81d1-f6aac369e96a", 1935 | "metadata": { 1936 | "tags": [] 1937 | }, 1938 | "outputs": [ 1939 | { 1940 | "data": { 1941 | "text/plain": [ 1942 | "\u001b[1;31mInit signature:\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m/\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 1943 | "\u001b[1;31mDocstring:\u001b[0m \n", 1944 | "range(stop) -> range object\n", 1945 | "range(start, stop[, step]) -> range object\n", 1946 | "\n", 1947 | "Return an object that produces a sequence of integers from start (inclusive)\n", 1948 | "to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.\n", 1949 | "start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.\n", 1950 | "These are exactly the valid indices for a list of 4 elements.\n", 1951 | "When step is given, it specifies the increment (or decrement).\n", 1952 | "\u001b[1;31mType:\u001b[0m type\n", 1953 | "\u001b[1;31mSubclasses:\u001b[0m " 1954 | ] 1955 | }, 1956 | "metadata": {}, 1957 | "output_type": "display_data" 1958 | } 1959 | ], 1960 | "source": [ 1961 | "len?" 1962 | ] 1963 | }, 1964 | { 1965 | "cell_type": "markdown", 1966 | "id": "e5530a60-ec98-4972-b108-3da311455ed9", 1967 | "metadata": {}, 1968 | "source": [ 1969 | "Range has following 3 parts.\n", 1970 | "- start\n", 1971 | "- stop\n", 1972 | "- interval if .-ive then reverse otherwise forward" 1973 | ] 1974 | }, 1975 | { 1976 | "cell_type": "markdown", 1977 | "id": "8c51660c-dd53-407b-bb67-492533a5d4a9", 1978 | "metadata": {}, 1979 | "source": [ 1980 | "### Forward Loop" 1981 | ] 1982 | }, 1983 | { 1984 | "cell_type": "code", 1985 | "execution_count": 69, 1986 | "id": "6f592b5d-70e2-461b-9a53-73aab6aa426d", 1987 | "metadata": { 1988 | "tags": [] 1989 | }, 1990 | "outputs": [ 1991 | { 1992 | "name": "stdout", 1993 | "output_type": "stream", 1994 | "text": [ 1995 | "5 x 1 = 5\n", 1996 | "5 x 2 = 10\n", 1997 | "5 x 3 = 15\n", 1998 | "5 x 4 = 20\n", 1999 | "5 x 5 = 25\n", 2000 | "5 x 6 = 30\n", 2001 | "5 x 7 = 35\n", 2002 | "5 x 8 = 40\n", 2003 | "5 x 9 = 45\n", 2004 | "5 x 10 = 50\n" 2005 | ] 2006 | } 2007 | ], 2008 | "source": [ 2009 | "table_of = 5\n", 2010 | "# Start, Stop, Interval\n", 2011 | "for val in range(1,11, 1):\n", 2012 | " print (f\"{table_of} x {val} = {val * table_of}\")" 2013 | ] 2014 | }, 2015 | { 2016 | "cell_type": "markdown", 2017 | "id": "33df9737-9fa9-4a74-a7a8-5ad45a4c2103", 2018 | "metadata": {}, 2019 | "source": [ 2020 | "### Reverse Loop" 2021 | ] 2022 | }, 2023 | { 2024 | "cell_type": "code", 2025 | "execution_count": 70, 2026 | "id": "a434bcb1-69c4-49c6-a848-621521917e25", 2027 | "metadata": { 2028 | "tags": [] 2029 | }, 2030 | "outputs": [ 2031 | { 2032 | "name": "stdout", 2033 | "output_type": "stream", 2034 | "text": [ 2035 | "10\n", 2036 | "9\n", 2037 | "8\n", 2038 | "7\n", 2039 | "6\n", 2040 | "5\n", 2041 | "4\n", 2042 | "3\n", 2043 | "2\n", 2044 | "1\n" 2045 | ] 2046 | } 2047 | ], 2048 | "source": [ 2049 | "# Start, Stop, Interval\n", 2050 | "for val in range(10,0, -1):\n", 2051 | " print (val)" 2052 | ] 2053 | }, 2054 | { 2055 | "cell_type": "code", 2056 | "execution_count": 21, 2057 | "id": "b57c3f38-f602-4e25-9217-20fb897d6996", 2058 | "metadata": { 2059 | "tags": [] 2060 | }, 2061 | "outputs": [ 2062 | { 2063 | "data": { 2064 | "text/plain": [ 2065 | "3" 2066 | ] 2067 | }, 2068 | "execution_count": 21, 2069 | "metadata": {}, 2070 | "output_type": "execute_result" 2071 | } 2072 | ], 2073 | "source": [] 2074 | }, 2075 | { 2076 | "cell_type": "markdown", 2077 | "id": "a69c9539-8c45-489b-a9be-f2dd65a3307b", 2078 | "metadata": {}, 2079 | "source": [ 2080 | "## File Operations" 2081 | ] 2082 | }, 2083 | { 2084 | "cell_type": "markdown", 2085 | "id": "919fd215-2aee-46e3-b4d8-573678e4b985", 2086 | "metadata": {}, 2087 | "source": [ 2088 | "### Read and Write" 2089 | ] 2090 | }, 2091 | { 2092 | "cell_type": "code", 2093 | "execution_count": 194, 2094 | "id": "5b1d9cd0-4759-4d39-9c04-5ca42bff68d1", 2095 | "metadata": { 2096 | "tags": [] 2097 | }, 2098 | "outputs": [ 2099 | { 2100 | "name": "stdout", 2101 | "output_type": "stream", 2102 | "text": [ 2103 | "['1\\n', '2\\n', '3']\n" 2104 | ] 2105 | } 2106 | ], 2107 | "source": [ 2108 | "f = open(\"data/sample.txt\", \"r\") # r to read or w to write\n", 2109 | "data = f.readlines()\n", 2110 | "f.close()\n", 2111 | "print(data)" 2112 | ] 2113 | }, 2114 | { 2115 | "cell_type": "code", 2116 | "execution_count": 73, 2117 | "id": "bc825986-1526-42fa-a033-d15b20c1d59f", 2118 | "metadata": { 2119 | "tags": [] 2120 | }, 2121 | "outputs": [ 2122 | { 2123 | "name": "stdout", 2124 | "output_type": "stream", 2125 | "text": [ 2126 | "Data Science and Marketing WebsitesWelcome to my website on Digital Marketing!\n" 2127 | ] 2128 | } 2129 | ], 2130 | "source": [ 2131 | "title = \"Data Science and Marketing Websites\"\n", 2132 | "content = \"Welcome to my website on Digital Marketing!\"\n", 2133 | "generator = f\"{title}{content}\"\n", 2134 | "print(generator)\n", 2135 | "\n", 2136 | "f = open(\"data/index.html\", \"w\") # r to read or w to write\n", 2137 | "f.write(generator)\n", 2138 | "f.close()" 2139 | ] 2140 | }, 2141 | { 2142 | "cell_type": "markdown", 2143 | "id": "d9020a03-d225-4af3-af7a-d4b45b047d24", 2144 | "metadata": {}, 2145 | "source": [ 2146 | "### Context Managers" 2147 | ] 2148 | }, 2149 | { 2150 | "cell_type": "code", 2151 | "execution_count": 74, 2152 | "id": "780179e5-e68a-4532-a2f1-aabf3bf35f13", 2153 | "metadata": { 2154 | "tags": [] 2155 | }, 2156 | "outputs": [ 2157 | { 2158 | "name": "stdout", 2159 | "output_type": "stream", 2160 | "text": [ 2161 | "['1\\n', '2\\n', '3']\n" 2162 | ] 2163 | } 2164 | ], 2165 | "source": [ 2166 | "# r to read or w to write\n", 2167 | "\n", 2168 | "with open(\"data/sample.txt\", \"r\") as f:\n", 2169 | " data = f.readlines() # f.readline(), f.readlines()\n", 2170 | " print (data)" 2171 | ] 2172 | }, 2173 | { 2174 | "cell_type": "markdown", 2175 | "id": "18b4da43-e108-49b4-acaa-2eedb9899c18", 2176 | "metadata": {}, 2177 | "source": [ 2178 | "## Scripts\n", 2179 | "\n", 2180 | "Folllowing always requrire you to have a :\n", 2181 | "- context manager\n", 2182 | "- if else conditions\n", 2183 | "- loops " 2184 | ] 2185 | }, 2186 | { 2187 | "cell_type": "code", 2188 | "execution_count": 198, 2189 | "id": "8d880967-a47a-42fb-b209-9964c09218fd", 2190 | "metadata": { 2191 | "tags": [] 2192 | }, 2193 | "outputs": [ 2194 | { 2195 | "name": "stdout", 2196 | "output_type": "stream", 2197 | "text": [ 2198 | "static wordpress\n" 2199 | ] 2200 | } 2201 | ], 2202 | "source": [ 2203 | "loc = \"https://www.seowings.org/static-wordpress/\"\n", 2204 | "\n", 2205 | "#pep8\n", 2206 | "loc = loc.replace(\"https://www.seowings.org/\",\"\")\n", 2207 | "loc = loc.replace(\"-\", \" \")\n", 2208 | "keyword = loc.replace(\"/\", \"\")\n", 2209 | "\n", 2210 | "print(keyword)" 2211 | ] 2212 | }, 2213 | { 2214 | "cell_type": "markdown", 2215 | "id": "d9127324-d663-431e-9810-a6001969bf83", 2216 | "metadata": {}, 2217 | "source": [ 2218 | "## Functions" 2219 | ] 2220 | }, 2221 | { 2222 | "cell_type": "code", 2223 | "execution_count": 199, 2224 | "id": "d004f792-5158-4e8a-b8d1-d054c28aba88", 2225 | "metadata": { 2226 | "tags": [] 2227 | }, 2228 | "outputs": [], 2229 | "source": [ 2230 | "def profit_loss_calculator():\n", 2231 | " pass\n", 2232 | "\n", 2233 | "def website_generator(title=\"Default Title\", content=\"Default Content\"):\n", 2234 | " generator = f\"{title}{content}\"\n", 2235 | " print(generator)\n", 2236 | "\n", 2237 | "def ctr_estimatation():\n", 2238 | " pass" 2239 | ] 2240 | }, 2241 | { 2242 | "cell_type": "code", 2243 | "execution_count": 200, 2244 | "id": "57878b92-3bc5-4509-b093-a2e494c8dbd0", 2245 | "metadata": { 2246 | "tags": [] 2247 | }, 2248 | "outputs": [], 2249 | "source": [ 2250 | "# 3 is default value\n", 2251 | "# 4 is also default value for Value2 variable\n", 2252 | "\n", 2253 | "def add(value1=3, value2=4): # 255 arguments\n", 2254 | " print (value1 + value2)" 2255 | ] 2256 | }, 2257 | { 2258 | "cell_type": "code", 2259 | "execution_count": 201, 2260 | "id": "619abb17-1016-4625-bacd-023dd0e6828c", 2261 | "metadata": { 2262 | "tags": [] 2263 | }, 2264 | "outputs": [ 2265 | { 2266 | "name": "stdout", 2267 | "output_type": "stream", 2268 | "text": [ 2269 | "This is titleDefault Content\n" 2270 | ] 2271 | } 2272 | ], 2273 | "source": [ 2274 | "mywebsite_title = \"This is title\"\n", 2275 | "mywebsite_content = \"This is an awesome contnet about Prompt Engineerin\"\n", 2276 | "website_generator(title=mywebsite_title)" 2277 | ] 2278 | }, 2279 | { 2280 | "cell_type": "code", 2281 | "execution_count": 202, 2282 | "id": "d88f83c3-c0e4-49c3-9766-61c82e8769be", 2283 | "metadata": { 2284 | "tags": [] 2285 | }, 2286 | "outputs": [ 2287 | { 2288 | "name": "stdout", 2289 | "output_type": "stream", 2290 | "text": [ 2291 | "7\n", 2292 | "7\n" 2293 | ] 2294 | } 2295 | ], 2296 | "source": [ 2297 | "add(3,4)\n", 2298 | "add(value2=4)" 2299 | ] 2300 | }, 2301 | { 2302 | "cell_type": "code", 2303 | "execution_count": 203, 2304 | "id": "fea1c791-4ab6-47a2-a1f1-baaa9e9cd186", 2305 | "metadata": { 2306 | "tags": [] 2307 | }, 2308 | "outputs": [], 2309 | "source": [ 2310 | "# newbies approach\n", 2311 | "def extact_sponsored_urls_from_page_1():\n", 2312 | " pass\n", 2313 | "\n", 2314 | "def extact_sponsored_urls_from_page_2():\n", 2315 | " pass\n", 2316 | "\n", 2317 | "def extact_sponsored_urls_from_page_3():\n", 2318 | " pass" 2319 | ] 2320 | }, 2321 | { 2322 | "cell_type": "code", 2323 | "execution_count": 204, 2324 | "id": "a1df6efa-9102-431a-a702-ac9f4078152d", 2325 | "metadata": { 2326 | "tags": [] 2327 | }, 2328 | "outputs": [], 2329 | "source": [ 2330 | "# sensible approach\n", 2331 | "def extract_sponsored_urls_from_google(page_id=1):\n", 2332 | " pass\n", 2333 | "\n", 2334 | "extract_sponsored_urls_from_google(page_id=1)\n", 2335 | "extract_sponsored_urls_from_google() # default value will be used" 2336 | ] 2337 | }, 2338 | { 2339 | "cell_type": "code", 2340 | "execution_count": 205, 2341 | "id": "03b736de-5910-47f4-a26e-e831df93b7cc", 2342 | "metadata": { 2343 | "tags": [] 2344 | }, 2345 | "outputs": [], 2346 | "source": [ 2347 | "# call the functions multiple time with differnt arguemtns\n", 2348 | "extract_sponsored_urls_from_google(page_id=1)\n", 2349 | "extract_sponsored_urls_from_google(page_id=2)\n", 2350 | "extract_sponsored_urls_from_google(page_id=3)\n", 2351 | "extract_sponsored_urls_from_google(page_id=4)\n", 2352 | "extract_sponsored_urls_from_google(page_id=5)\n", 2353 | "\n", 2354 | "# sensible approach\n", 2355 | "def extract_sponsored_urls_from_google(page_id=1):\n", 2356 | " pass\n", 2357 | "\n", 2358 | "# for loops \n", 2359 | "for page_id in [1,2,3,4,5]:\n", 2360 | " extract_sponsored_urls_from_google(page_id)" 2361 | ] 2362 | }, 2363 | { 2364 | "cell_type": "code", 2365 | "execution_count": 76, 2366 | "id": "72be08f7-e601-4e62-899d-941a8220b816", 2367 | "metadata": { 2368 | "tags": [] 2369 | }, 2370 | "outputs": [ 2371 | { 2372 | "name": "stdout", 2373 | "output_type": "stream", 2374 | "text": [ 2375 | "Extracting Sponsor URLS from Google on Page 1\n", 2376 | "Extracting Sponsor URLS from Google on Page 2\n", 2377 | "Extracting Sponsor URLS from Google on Page 3\n", 2378 | "Extracting Sponsor URLS from Google on Page 4\n", 2379 | "Extracting Sponsor URLS from Google on Page 5\n", 2380 | "Extracting Sponsor URLS from Google on Page 10\n" 2381 | ] 2382 | } 2383 | ], 2384 | "source": [ 2385 | "def extract_sponsored_urls_from_google(page_id=1):\n", 2386 | " \"\"\"This function is used to extract sponsored urls form Google SERP\"\"\"\n", 2387 | " \n", 2388 | " print (f\"Extracting Sponsor URLS from Google on Page {page_id}\")\n", 2389 | " # any code which will extract urls form Google Page should work\n", 2390 | " # Any condition to classify the URLs\n", 2391 | " # Classify using if-else\n", 2392 | " # GERMAN\n", 2393 | " # COM\n", 2394 | " # ORG\n", 2395 | "\n", 2396 | "# for loops \n", 2397 | "page_numbers = [1,2,3,4,5, 10]\n", 2398 | "for page_id in page_numbers:\n", 2399 | " extract_sponsored_urls_from_google(page_id)" 2400 | ] 2401 | }, 2402 | { 2403 | "cell_type": "code", 2404 | "execution_count": 77, 2405 | "id": "528d7963-5a29-4266-acbf-61d0228f0b6e", 2406 | "metadata": { 2407 | "tags": [] 2408 | }, 2409 | "outputs": [ 2410 | { 2411 | "data": { 2412 | "text/plain": [ 2413 | "\u001b[1;31mSignature:\u001b[0m \u001b[0mextract_sponsored_urls_from_google\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpage_id\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 2414 | "\u001b[1;31mDocstring:\u001b[0m This function is used to extract sponsored urls form Google SERP\n", 2415 | "\u001b[1;31mFile:\u001b[0m c:\\users\\serpwings\\appdata\\local\\temp\\ipykernel_12512\\1967962205.py\n", 2416 | "\u001b[1;31mType:\u001b[0m function" 2417 | ] 2418 | }, 2419 | "metadata": {}, 2420 | "output_type": "display_data" 2421 | } 2422 | ], 2423 | "source": [ 2424 | "extract_sponsored_urls_from_google?" 2425 | ] 2426 | }, 2427 | { 2428 | "cell_type": "code", 2429 | "execution_count": 88, 2430 | "id": "1d3062e0-f489-4895-adc5-9ded25414507", 2431 | "metadata": { 2432 | "tags": [] 2433 | }, 2434 | "outputs": [ 2435 | { 2436 | "name": "stdout", 2437 | "output_type": "stream", 2438 | "text": [ 2439 | "https://archive.org/wayback/available?url=seowings.org×tamp=19900101\n", 2440 | "https://archive.org/wayback/available?url=seowings.org×tamp=19900401\n", 2441 | "https://archive.org/wayback/available?url=seowings.org×tamp=19900801\n", 2442 | "https://archive.org/wayback/available?url=seowings.org×tamp=20210101\n", 2443 | "https://archive.org/wayback/available?url=seowings.org×tamp=20210401\n", 2444 | "https://archive.org/wayback/available?url=seowings.org×tamp=20210801\n", 2445 | "https://archive.org/wayback/available?url=seowings.org×tamp=20230101\n", 2446 | "https://archive.org/wayback/available?url=seowings.org×tamp=20230401\n", 2447 | "https://archive.org/wayback/available?url=seowings.org×tamp=20230801\n" 2448 | ] 2449 | } 2450 | ], 2451 | "source": [ 2452 | "def extract_competitor_history(website_address):\n", 2453 | " \"\"\" This function extract history of a website \"\"\"\n", 2454 | " \n", 2455 | " month = \"01\"\n", 2456 | " day = \"01\"\n", 2457 | " for year in [\"1990\", \"2021\", \"2023\"]:\n", 2458 | " for month in [\"01\", \"04\", \"08\"]:\n", 2459 | " url = f\"https://archive.org/wayback/available?url={competitor}×tamp={year}{month}{day}\"\n", 2460 | " # data_of_archived = extract_if_archive_available(url)\n", 2461 | " print (url)\n", 2462 | " # register_history = whois(competitor)\n", 2463 | "\n", 2464 | "extract_competitor_history(website_address = \"seowings.org\")\n", 2465 | "extract_competitor_history(website_address = \"bestlaptops.com\")\n", 2466 | "extract_competitor_history(website_address = \"jang.com.pk\")" 2467 | ] 2468 | }, 2469 | { 2470 | "cell_type": "code", 2471 | "execution_count": null, 2472 | "id": "f220c7b3-e137-48e5-b0d9-51fe41276801", 2473 | "metadata": {}, 2474 | "outputs": [], 2475 | "source": [ 2476 | "for website_address in [\"seowings.org\",\"bestlaptops.com\", \"jang.com.pk\", \"serpwings.com\"]:\n", 2477 | " extract_competitor_history(website_address = )" 2478 | ] 2479 | }, 2480 | { 2481 | "cell_type": "code", 2482 | "execution_count": 93, 2483 | "id": "827fdd36-8c28-4dbc-94d8-685a1bd4648b", 2484 | "metadata": { 2485 | "tags": [] 2486 | }, 2487 | "outputs": [ 2488 | { 2489 | "data": { 2490 | "text/plain": [ 2491 | "dict" 2492 | ] 2493 | }, 2494 | "execution_count": 93, 2495 | "metadata": {}, 2496 | "output_type": "execute_result" 2497 | } 2498 | ], 2499 | "source": [ 2500 | "a = {\"3\": 3}\n", 2501 | "type(a)" 2502 | ] 2503 | }, 2504 | { 2505 | "cell_type": "code", 2506 | "execution_count": 94, 2507 | "id": "6fcbf778-067e-43e5-a911-c8c418c4afcd", 2508 | "metadata": { 2509 | "tags": [] 2510 | }, 2511 | "outputs": [ 2512 | { 2513 | "data": { 2514 | "text/plain": [ 2515 | "dict" 2516 | ] 2517 | }, 2518 | "execution_count": 94, 2519 | "metadata": {}, 2520 | "output_type": "execute_result" 2521 | } 2522 | ], 2523 | "source": [ 2524 | "sa = {1,2,3}\n", 2525 | "type(a)" 2526 | ] 2527 | }, 2528 | { 2529 | "cell_type": "code", 2530 | "execution_count": null, 2531 | "id": "f5dbcbab-d38b-47f9-9f1b-85621b90d427", 2532 | "metadata": { 2533 | "tags": [] 2534 | }, 2535 | "outputs": [], 2536 | "source": [] 2537 | } 2538 | ], 2539 | "metadata": { 2540 | "kernelspec": { 2541 | "display_name": "Python 3 (ipykernel)", 2542 | "language": "python", 2543 | "name": "python3" 2544 | }, 2545 | "language_info": { 2546 | "codemirror_mode": { 2547 | "name": "ipython", 2548 | "version": 3 2549 | }, 2550 | "file_extension": ".py", 2551 | "mimetype": "text/x-python", 2552 | "name": "python", 2553 | "nbconvert_exporter": "python", 2554 | "pygments_lexer": "ipython3", 2555 | "version": "3.10.11" 2556 | } 2557 | }, 2558 | "nbformat": 4, 2559 | "nbformat_minor": 5 2560 | } 2561 | --------------------------------------------------------------------------------