Python for Data Science Module 1
Module 1: Getting started with Data Science and Python
1.0. Discovering the match between data science and Python:
1.0.1. Discovering the Wonders of Data Science
Data Science is transforming the world by turning raw data into meaningful insights. It powers
recommendations on Netflix, personalized ads on social media, weather predictions, and even
financial risk analysis. At its core, data science is about asking the right questions, collecting relevant
data, and using computational techniques to extract knowledge and make informed decisions.
Some of the wonders of data science include:
• Predictive analytics to forecast trends and behaviours.
• Natural language processing (NLP) to understand and generate human language.
• Computer vision to analyze and interpret visual information.
• Automation and decision-making powered by intelligent algorithms.
These capabilities empower businesses, governments, healthcare, and nearly every other industry to
innovate and improve decision-making.
1.0.2. Exploring How Data Science Works
Data Science is not a single tool or algorithm—it's a process. The data science workflow typically
includes the following steps:
1. Data Collection
Gathering structured or unstructured data from databases, APIs, sensors, or web
scraping.
2. Data Cleaning & Preparation
Removing inconsistencies, handling missing values, formatting data, and converting it
into a usable form.
3. Exploratory Data Analysis (EDA)
Using statistics and visualization to uncover patterns, trends, and relationships.
4. Model Building
Applying machine learning algorithms to make predictions or classifications.
5. Evaluation & Optimization
Testing the model's accuracy and refining it to improve performance.
6. Communication
Presenting results using dashboards, visualizations, or reports that stakeholders can
understand and act upon.
This lifecycle helps transform raw data into actionable insights that drive strategic decisions.
1.0.3. Creating the Connection Between Python and Data Science
Prepared By: Asst Prof Swati Solanki 1 GUCPC
Python for Data Science Module 1
Python has become the de facto language of data science, and for good reasons:
• Simplicity and readability make it accessible to both beginners and professionals.
• Rich libraries such as:
✓ NumPy for numerical operations
✓ Pandas for data manipulation
✓ Matplotlib and Seaborn for data visualization
✓ Scikit-learn for machine learning
✓ TensorFlow and PyTorch for deep learning
• Community support: Python has a vast ecosystem of developers and data scientists
constantly creating and sharing tools and knowledge.
One of Python's key strengths is its ability to serve as a unifying language, allowing seamless
integration of data access, cleaning, analysis, modelling, and visualization in a single environment.
The book also emphasizes Python's modularity, which means you can start small and gradually
expand your toolkit as needed.
1.1. Setting Up Python for Data Science
Python Installation on Windows:
Step 1: Select Python Version
Deciding on a version depends on what you want to do in Python.
The two major versions are Python 2 and Python 3, but Python 2 is outdated and no longer
supported.
If you're working on a legacy project, you may need Python 2, but for everything else, Python 3 is
the better choice.
Also, choose a stable release over the newest one, as newer versions may have bugs and issues.
Step 2: Downloading the Python Installer
Prepared By: Asst Prof Swati Solanki 2 GUCPC
Python for Data Science Module 1
After clicking the Install Now Button, the setup will start installing Python on your Windows
system. You will see a window like this.
Step 3: Running the Executable Installer
Step 4: Verify the Python Installation in Windows
Close the window after the successful installation of Python. You can check if the installation of
Python was successful by using either the command line or the Integrated Development
Environment (IDLE).
Command > python –version
Prepared By: Asst Prof Swati Solanki 3 GUCPC
Python for Data Science Module 1
1.2. Understanding the tools:
→ Install PIP (Python's package installer)
Download [Link]
python [Link]
Verifying the pip installation on Windows
pip –version
To upgrade the existing pip version
python –m pip install - -upgrade pip
1.2.1. Using the Jupyter Console
The Python console is where you can experiment with data science interactively. You can try things
and see the results immediately. If you make a mistake, you can simply close the console and create
a new one. The console is for playing around and considering what might be possible.
Installing Jupyter Console
pip install jupyter-console
Starting with Jupyter console:
Prepared By: Asst Prof Swati Solanki 4 GUCPC
Python for Data Science Module 1
[Link]. Interacting with screen text
No one can remember absolutely everything about a programming language. Even the best coders
have memory lapses. This is why having language-specific help is so important.
The Python portion of the IPython console provides two methods of getting help: help mode and
interactive help.
[Link]. Getting Python help
Entering help mode
To enter help mode, type help( ) and press Enter. The console enters a new mode, in which you can
type help-related commands as needed to discover more about Python. You can’t type Python
commands in this mode. The prompt changes to a help> prompt, to remind you that you’re in help
mode.
To obtain help about any object or command, simply type the object or command name and press
Enter. You can also type any of the following commands to obtain a listing of other topics of
discussion.
modules: Compiles a list of the currently loaded modules. This list varies by how your copy of
Python (the underlying language) is configured at any given time, so the list won’t be the same every
Prepared By: Asst Prof Swati Solanki 5 GUCPC
Python for Data Science Module 1
time you use this command. The command can take a while to execute, and the output list is usually
quite large.
keywords: Presents a list of Python keywords that you can ask about. For example, you can type
assert and learn more about the assert keyword.
Prepared By: Asst Prof Swati Solanki 6 GUCPC
Python for Data Science Module 1
symbols: Shows the list of symbols that have special meaning in Python, such as * for multiplication
and << for a left shift.
topics: Displays a list of general Python topics, such as CONVERSIONS. The topics appear in
uppercase rather than lowercase
[Link]. Getting IPython help
Getting help with IPython is different from getting help with Python. When you obtain IPython help,
you work with the development environment rather than the programming language. To obtain
IPython help, type ? and press Enter. You see a long listing of the various ways in which you can
use IPython help.
Some of the more essential forms of help rely on typing a keyword with a question mark. For
example, if you want to learn more about the cls command, you type cls? or ?cls and press Enter. It
doesn’t matter whether the question mark appears before or after the command.
[Link]. Using magic functions
Amazingly, you really can get magic on your computer! Jupyter provides a special feature called
magic functions. The functions let you perform all sorts of amazing tasks with your Jupyter console.
Obtaining the magic functions list
The best way to start working with magic functions is to obtain a list of them by typing %quickref
and pressing Enter.
Prepared By: Asst Prof Swati Solanki 7 GUCPC
Python for Data Science Module 1
[Link]. Discovering objects
With IPython, you can request information about specific objects using the object name and a
question mark (?).
For example, if you want to know more about a list object named mylist, simply type mylist?
1.2.2. Using Jupyter Notebook
Installing Jupyter Notebook
Pip install jupyter
Starting with Jupyter notebook
Open Command Prompt and type> jupyter notebook
Prepared By: Asst Prof Swati Solanki 8 GUCPC
Python for Data Science Module 1
[Link]. Working with styles
Here’s one of the ways in which Notebook excels over just about any other IDE that you’ll ever use:
It helps you to create nice-looking output. Rather than have a screen full of a whole bunch of plain-
old code, you can use Notebook to create sections and add styles so that the output is nicely
formatted.
Prepared By: Asst Prof Swati Solanki 9 GUCPC
Python for Data Science Module 1
Prepared By: Asst Prof Swati Solanki 10 GUCPC
Python for Data Science Module 1
[Link]. Restarting the kernel
Every time you perform a task in your notebook, you create variables, import modules, and perform
a wealth of other tasks that corrupt the environment. At some point, you can’t really be sure that
something is working as it should. To overcome this problem, you click Restart Kernel (the button
with an open circle with an arrow at one end) after saving your document by clicking Save and
Checkpoint (the button containing a floppy disk symbol). You can then run your code again to ensure
that it does work as you thought it would.
[Link]. Restoring a checkpoint
At some point, you may find that you made a mistake. Notebook is notably missing an Undo button:
You won’t find one anywhere. Instead, you create checkpoints each time you finish a task. Creating
checkpoints when your document is stable and working properly helps you recover faster from
mistakes.
To restore your setup to the condition contained in a checkpoint, choose File Revert to Checkpoint.
You see a listing of available checkpoints.
Prepared By: Asst Prof Swati Solanki 11 GUCPC
Python for Data Science Module 1
[Link]. Performing Multimedia and Graphic Integration
Pictures say a lot of things that words can’t say (or at least they do it with far less effort). Notebook
is both a coding platform and a presentation platform. You may be surprised at just what you can do
with it.
[Link].1. Embedding plots and other images
At some point, you might have spotted a notebook with multimedia or graphics embedded into it
and wondered why you didn’t see the same effects in your own files. In fact, all the graphics
examples in the book appear as part of the code. Fortunately, you can perform some more magic by
using the %matplotlib magic function. The possible values for this function are: ’gtk’, ’gtk3’,
’inline’, ’nbagg’, ’osx’, ’qt’, ’qt4’, ’qt5’, ’tk’, and ’wx’, each of which defines a different plotting
backend (the code used to actually render the plot) used to present information onscreen.
Prepared By: Asst Prof Swati Solanki 12 GUCPC
Python for Data Science Module 1
[Link].2. Loading examples from online sites
Because some examples you see online can be hard to understand unless you have them loaded on
your own system, you should also keep the %load magic function in mind. All you need is the URL
of an example you want to see on your system. For example, try %load
[Link] When you click Run Cell, Notebook loads the
example directly in the cell and comments the %load call out. You can then run the example and see
the output from it on your own system.
%load [Link]
Prepared By: Asst Prof Swati Solanki 13 GUCPC
Python for Data Science Module 1
[Link].3. Obtaining online graphics and multimedia
A lot of the functionality required to perform special multimedia and graphics processing appears
within [Link]. By importing a required class, you can perform tasks such as embedding
images into your notebook.
Prepared By: Asst Prof Swati Solanki 14 GUCPC