1
EXPERIMENT 1
Aim: - Introduction and installation of Python and PythonIDEs for
data science (Spyder- Anaconda, Jupyter Notebook etc.)
Introduction to Python for Data Science:
Python is one of the most popular programming languages for data
science due to its simplicity, readability, and the large ecosystem of
libraries that support data manipulation, statistical analysis,
machinelearning, and visualization.
Key Features of Python for Data Science:
1. Simple and Readable: Python’s syntax is clean and easyto
understand, making it beginner-friendly.
2. Versatile: It has a wide range of libraries such as NumPy,
pandas, Matplotlib, and scikit-learn which arespecifically
tailored for data science tasks.
3. Cross-platform: It runs on different platforms like
Windows, macOS, and Linux, allowing flexibility.
4. Large Community: Python has a vast community, ensuring
continuous updates, support, and resources.
Installing Python for Data Science:
Python can be installed from its official website, but it’sbetter to
install a distribution like Anaconda, which comes with all the
essential libraries and tools
pre-installed.
Steps to Install Python (Anaconda):
• Download Anaconda:
• Go to the [Anaconda website]
Piyush Arora 00896211923 AI&DS (3rd Sem)
2
(https://www.anaconda.com/products/individual).
• Download the version compatible with your operating system
(Windows, macOS, or Linux).
• Install Anaconda:
• Follow the installation instructions for your
operating system. The process is straightforward,
with default options being ideal for most users.
• Verify the Installation:
• After installation, open the terminal or command
prompt and type `conda --version` to check if
Anaconda is installed correctly.
Piyush Arora 00896211923 AI&DS (3rd Sem)
3
Piyush Arora 00896211923 AI&DS (3rd Sem)
4
Python IDEs for Data Science:
Piyush Arora 00896211923 AI&DS (3rd Sem)
5
Different Integrated Development Environments (IDEs)offer various
features that make coding in Python for data science easier.
1. Spyder (Anaconda)
Spyder (Scientific Python Development Environment) isan IDE
that comes pre-installed with Anaconda. It's designed specifically
for data science and scientific computing.
Features:
• A clean and minimalist interface.
• Integration with IPython (an enhanced interactivePython
shell).
• Variable explorer for inspecting data variables.
• Built-in support for debugging.
Installation:
● Spyder comes pre-installed with Anaconda. After installing
Anaconda, you can launch Spyder via theAnaconda
Navigator or by typing `spyder` in your terminal/command
prompt.
Piyush Arora 00896211923 AI&DS (3rd Sem)
6
2. Jupyter Notebook
Jupyter Notebook is one of the most popular environments for
data science. It allows you to createand share documents that
contain live code, visualizations, and text in markdown format.
Features:
● Interactive environment: Code cells are executed oneby one,
making it perfect for experimentation.
● Inline visualizations: Visualize data using Matplotlib,Seaborn,
or Plotly directly in the notebook.
● Supports multiple languages: Python, R, and Julia,among
others.
● Export to HTML or PDF.
Installation:
● Jupyter Notebook also comes pre-installed with Anaconda.
You can launch it from the Anaconda Navigator or by
Piyush Arora 00896211923 AI&DS (3rd Sem)
7
running ‘Jupyter notebook’ in yourterminal/command
prompt.
3. VS Code (with Python Extension)
Visual Studio Code is a lightweight, customizable IDE that
supports multiple programming languages, includingPython. While
not pre-installed with Anaconda, it can easily be configured for
Python.
Features:
• Intelligent code completion and debugging tools.
• Integrated terminal for running scripts.
• Support for Jupyter notebooks with the Pythonextension.
• Extensions for many tools and libraries (e.g., linting,Git
integration).
Piyush Arora 00896211923 AI&DS (3rd Sem)
8
Installation:
● Download VS Code from its [official website]
(https://code.visualstudio.com/).
● After installation, install the Python extension fromthe
Extensions marketplace.
● Optionally, you can install Jupyter extension if you'dlike to
work with Jupyter notebooks in VS Code.
Summary of Steps for Practical Data Science Environment
Setup:
1. Install Anaconda: Comes with Python and data sciencetools like
Spyder and Jupyter Notebook.
2. Launch Spyder or Jupyter Notebook from the
Anaconda Navigator to start coding.
3. For more flexibility, install and set up VS Code withPython
extensions.
Piyush Arora 00896211923 AI&DS (3rd Sem)
9
Experiment 2
Aim: - Design a Python program to generate and print alist except
for the first 5 elements, where the values aresquares of numbers
between 1 and 30.
PYTHON CODE:
l = []
for i in range(1,31):
l.append(i*i)
print(l[5:])
EXPLANATION:
● List comprehension is used to generate the squares of numbers
from 1 to 30 (x2 where x is in the range 1 to 30).
● squares[5:] slices the list to exclude the first 5 elements (indexing
starts at 0 in Python).
OUTPUT:
LEARNING OUTCOME:
We successfully generated Python program to generate and print a list
except for the first 5 elements, where the values are squares of numbers
between 1 and 30.
Piyush Arora 00896211923 AI&DS (3rd Sem)
10
EXPERIMENT 3
Aim: - Design a Python program to understand the working of
loops.
PYTHON CODE:
#for loop.
print("Output using for loop")
for i in range(5):
print(i,end = "") #it will print all no.s less than 5
print("\n")
# while loop
print("Output using while loop")
j=0
while (j<=5):
print(j,end="") # it will run the loop until condition remains true, print
from 0 to 5
j+=1
EXPLANATION:
For Loop:
• For I in range(5): This line sets up a for loop that will iterate over a
range of numbers from 0 to 4(i.e., less than 5). range(5) generates the
sequence 0,1,2,3,4.
• print(i, end=” “): This prints each value of i in the loop on the same
line without a space between them(because end =”” removes the
default newline character).
Piyush Arora 00896211923 AI&DS (3rd Sem)
11
• print(“\n”): After the loop completes, this prints a newline character to
move to the next line
While loop:
• j = 0: This initializes the variable j to 0.
• while (j <= 5):: This sets up a while loop that will continue to execute a
s long as j is less than or equal to 5.
• print(j, end=""): This prints the current value of j on the same line with
out a space between them.
• j += 1: This increments the value of j by 1 after each loop iteration.
OUTPUT:
LEARNING OUTCOME:
We have learned the working of loops (for loop and while
loop).
Piyush Arora 00896211923 AI&DS (3rd Sem)
12
Experiment 4
Aim: - Design a Python function to find the Max of three
numbers.
PYTHON CODE:
def max(a,b,c):
if (a>b and a>c):
print("Maximum no. is: ",a)
elif(b>c and b>a):
print("Maximum no. is: ",b)
else:
print("Maximum no. is: ",c)
num1 = int(input("Enter First no.: "))
num2 = int(input("Enter Second no.: "))
num3 = int(input("Enter Third no.: "))
max(num1,num2,num3)
EXPLANATION:
This function takes three arguments (a, b, and c) and checks
three conditions
1. a>b and a>c: Checks for ‘a’ if a is greater than both b and c
then print maximum no. as ‘a’.
2. b>c and b>a: Checks for ‘b’ if a is greater than both b and c
then print maximum no. as ‘b’.
3. If upper two conditions does not match then it print ‘c’ as
maximum.
Piyush Arora 00896211923 AI&DS (3rd Sem)
13
OUTPUT:
LEARNING OUTCOME:
We have successfully learned working of loops.
Piyush Arora 00896211923 AI&DS (3rd Sem)
14
EXPERIMENT 5
Aim :- Design a Python program for creating a random story
generator.
PYTHON CODE:
import random
characters = ["a dragon", "an astronaut", "a pirate", "a detective"]
settings = ["in space", "on a deserted island", "in an ancient castle", "in a
bustling city"]
conflicts = ["is searching for a hidden treasure", "is trying to solve a
mystery", "is on a quest to save the world", "is learning to control their
powers"]
def generate_story():
character = random.choice(characters)
setting = random.choice(settings)
conflict = random.choice(conflicts)
story = f"Once upon a time, {character} {setting} {conflict}."
return story
print(generate_story())
EXPLANATION :
The generate_story() function randomly selects one element from
the lists of characters, settings, and conflicts using
random.choice(), and combines them into a sentence. It
constructs a story in the format: "Once upon a time, [character]
Piyush Arora 00896211923 AI&DS (3rd Sem)
15
[setting] [conflict]." This creates a new, random story each time
the function is called.
OUTPUT :
LEARNING OUTCOME:
Successfully generated the story by creating story generating
function.
Piyush Arora 00896211923 AI&DS (3rd Sem)
16
EXPERIMENT 6
Aim: - Create a synthetic dataset (.csv/.xlsx) to work upon and
design a Python program to read and print that data.
I have created a synthetic dataset with basic information such as
name, age, department, salary, and years of experience. You can
download the dataset in either CSV or Excel format.
PYTHON CODE: -
import pandas as pd
csv_data = pd.read_csv('synthetic_dataset.csv')
print("Data from CSV file:")
print(csv_data)
Piyush Arora 00896211923 AI&DS (3rd Sem)
17
OUTPUT :
LEARNING OUTCOME:
Learned to create a csv/xlsx file and read and print the data using
pandas library.
Piyush Arora 00896211923 AI&DS (3rd Sem)