0% found this document useful (0 votes)
13 views20 pages

Lab Sneha

Uploaded by

newzzage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views20 pages

Lab Sneha

Uploaded by

newzzage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

JSPM UNIVERSITY PUNE

Faculty of Science and Technology


School of Basic and Applied Sciences
MCA/M.Sc. DS&AI/M.Sc. Cyber Security F. Y.
A.Y 2023-24

Name : Sneha Sunil


Sankeshwari
Roll No : 60

Subject : Data Science with Python


JSPM UNIVERSITY PUNE
Faculty of Science and Technology
School of Basic and Applied Sciences

CERTIFICATE
This is to certify that Mr.Dheeraj Basavaraj Iti bearing roll no. 28 of MCA

F. Y. semester II from School of Basic and Applied Sciences has

satisfactorily completed Data Science with Python laboratory course code

230GCAM16_02 during the academic year 2023-24.

Course Incharge Program Co-ordinator Dean


JSPM UNIVERSITY PUNE
School of Basic and Applied Sciences

INDEX
Exp Date of
. Title of Experiment Execution Sign.
no.
1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.
Lab No. 1&2
Q1) Implement a python program to display the current data and time.

import datetime
now=datetime.datetime.now()
print("current date and time:")
print(now.strftime("%y-%m-%d %H:%M:%S"))

Output:-
Q2) Implement a python program that calculates the area of a circle based on the radius
entered by the user.

r=int(input('Enter the radius of the circle:'))


area=3.14*r*r
print(area)

Output:-
Lab No. 3,4,5,6

Q1) Implement a python program to multiply matrices

x=[[12,7,3],
[4,5,6],
[7,8,9]]
y=[[5,4,6,2],
[3,7,8,1],
[1,2,3,4]]
r=[[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(x)):
for j in range(len(y[0])):
for k in range(len(y)):
r[i][j]+=x[i][k]*y[k][j]
for r1 in r:
print(r1)

Output:-
Q2) Implement a python program that accepts a sequence of comma-separated numbers
from the user and generates a list and a tuple of those numbers.

numbers=input('Enter comma-seprated numbers:')


numbers_list=numbers.split(',')
numbers_tuple=tuple(numbers_list)
print("list of numbers:",numbers_list)
print("Tuple of numbers:",numbers_tuple)

Output:-
Q3) Implement function overloading with differnt function signatures

class OverloadedFunctions:
def _init_(self):
pass
def add(self, a, b):
return a + b
def add(self, a, b, c):
return a + b + c
functions =
OverloadedFunctions() result1 =
functions.add(2, 3) result2 =
functions.add(2, 3, 4) print(result1,
result2)

Output:-
Q4) Implementation concept of class,instances and inheritance

class Animal:
def speak(self):
print("Animal Speaking")

class Dog(Animal):
def bark(self):
print("dog barking")
d = Dog()
d.bark()
d.speak()

Output:-
Lab 7 & 8
Q1) Write a python program that takes a text file as input and returns the number of
words of a given text file

def count_words(s):
with open(s) as f:
data=f.read()
data.replace(","," ")
return len(data.split(" "))
print(count_words("s.txt"))

Output:-
Q2) Write a python program to check in which directory you are working.

import os
print(os.getcwd())

Output:-
Lab 9, 10 & 11

Q1) Implement python program using a numpy module create an array and check the
following:Types of array,Axix of array,shape of the array and types of elements in
array

import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print("Array:")
print(arr)
print("\nType of array:", type(arr))
print("\nNumber of axes (dimensions) of the array:", arr.ndim)
print("\nShape of the array:", arr.shape)
print("\nType of elements in the array:", arr.dtype)

Output:-
Q2) Implement python program using mumpy array inexing to access the element on
the 2nd row,5th column.

import numpy as np
arr = np.array([[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]])
element = arr[1, 4]
print("Element at the 2nd row, 5th column:", element)

Output:-
Q3) Implement python program using numpy array reshape from 1D to 2D

import numpy as np
arr_1d = np.array([1, 2, 3, 4, 5, 6, 7,
8]) arr_2d = arr_1d.reshape(2, 4)
print("Original 1D array:")
print(arr_1d)
print("\nReshaped 2D array:")
print(arr_2d)

Output:-
Lab 12, 13, 14 & 15

Q1) Write a Python program to plot two or more lines with different styles.

import matplotlib.pyplot as plt


x = [1, 2, 3, 4, 5]
y1 = [2, 4, 6, 8, 10]
y2 = [1, 3, 5, 7, 9]
plt.plot(x, y1, linestyle='-', label='Line 1') # Solid line
plt.plot(x, y2, linestyle='--', label='Line 2') # Dashed line
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Multiple Lines Plot with Different Styles')
plt.legend()
plt.show()

Output:-
Q2) Write a Python program to draw line charts of the financial data of Alphabet Inc.
between October 3, 2016 to October 7, 2016. Sample Financial data (fdata.csv):
Date,Open,High,Low,Close 10-03-16,774.25,776.065002,769.5,772.559998 10-04-
16,776.030029,778.710022,772.890015,776.429993
10-05-16,779.309998,782.070007,775.650024,776.469971 10-06-
16,779,780.47998,775.539978,776.859985 10-07-
16,779.659973,779.659973,770.75,775.080017

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('fdata.csv')
df['Date'] = pd.to_datetime(df['Date'], format='%m-%d-%y')
start_date = '2016-10-03'
end_date = '2016-10-07'
filtered_df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
plt.figure(figsize=(10, 6))
plt.plot(filtered_df['Date'], filtered_df['Close'], marker='o', linestyle='-')
plt.title('Alphabet Inc. Stock Prices (Oct 3, 2016 - Oct 7, 2016)')
plt.xlabel('Date')
plt.ylabel('Closing Price')
plt.grid(True)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

Output:-
Q3) Write a Python programming to display a bar chart of the popularity of
programming Languages. Use different color for each bar. Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7

import matplotlib.pyplot as plt


languages = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++']
popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
colors = ['blue', 'orange', 'green', 'red', 'purple', 'brown']
plt.figure(figsize=(10, 6))
plt.bar(languages, popularity, color=colors)
plt.title('Popularity of Programming Languages')
plt.xlabel('Programming Languages')
plt.ylabel('Popularity (%)')
plt.show()

Output:-
Q4) Write a Python programming to display a bar chart of the popularity of
programming Languages. Select the width of each bar and their positions. Sample
data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7

import matplotlib.pyplot as plt


languages = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++']
popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
bar_width = 0.5 # Adjust this value to change the width of the bars
bar_positions = range(len(languages))
plt.figure(figsize=(10, 6))
plt.bar(bar_positions, popularity, width=bar_width, color='skyblue')
plt.title('Popularity of Programming Languages')
plt.xlabel('Programming Languages')
plt.ylabel('Popularity (%)')
plt.xticks(bar_positions, languages)
plt.show()

Output:-
Q5) Write a Python programming to create a pie chart with a title of the popularity of
programming Languages.Make multiple wedges of the pie. Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7

import matplotlib.pyplot as plt


languages = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++']
popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
plt.figure(figsize=(8, 8))
plt.pie(popularity, labels=languages, autopct='%1.1f%%', startangle=140)
plt.title('Popularity of Programming Languages')
plt.axis('equal')
plt.show()

Output:-
Q6) Write a Python program to draw a scatter plot comparing two subject
marks of Mathematics and Science. Use marks of 10 students. Sample data: Test
Data: math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30] marks_range = [10, 20,
30, 40, 50, 60, 70, 80, 90, 100]

import matplotlib.pyplot as plt


math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
plt.figure(figsize=(8, 6))
plt.scatter(marks_range, math_marks, color='blue', label='Math Marks')
plt.scatter(marks_range, science_marks, color='green', label='Science Marks')
plt.title('Scatter Plot of Mathematics and Science Marks')
plt.xlabel('Marks
Range')
plt.ylabel('Marks')
plt.legend()
plt.grid(True)
plt.show()

Output:-

You might also like