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

Lab Manual - V20UDS401 Programming For Analytics

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)
76 views20 pages

Lab Manual - V20UDS401 Programming For Analytics

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

Directorate of Online Education

SRM Institute of Science and

Technology SRM Nagar, Kattankulathur-

603203

LAB MANUAL

Course :BCA

SEMESTER- IV

SUBJECTTITL

E
Programming for Analytics

SUBJECT
CODE
V20UDS401

Prepared By
Dr.S.Umarani
Professor, Department of Computer Science and
Applications(BScCS) SRM IST

Directorate of Online Education


OBJECTIVES

1. To introduce students to the basic knowledge of Programming development

2. To impart writing skill of programming to the students and solving problems.

3. To impart the concepts like Data Types, Looping, Statistics methods, Function
Files, Inheritance, Data Visualization, Data Aggregation and merging two datasets

COURSE OUTCOME

1. Able to write relatively advanced, well structured, computer programs


in Python
2. Familiar with principles and techniques for optimizing the performance
of python numeric applications
3. Able to implement object oriented Programming
4. Able to implement database and GUI applications
5. Able to analysis the data
6. Able to understand visualization and data projections

INTRODUCTION ABOUT VIRTUAL LAB

Virtual Lab Content is prepared by Course Coordinator of concern subject to


help the students with their practical understanding and development of
programming skills, and may be used as a base reference during the Practical
Assignments. The model lab programs and List of Exercise Assignment prepared
by staff members will be upload in LMS .Students have to submit Lab Exercise
through LMS as Assignment Sections as Separate Folder of concern subject . The
course coordinator of concern subject can be evaluated after students submit all
program assignments for end semester sectional examination.. The lab Program
reporting style in the prescribed format (Appendix-I) and List of Lab Exercises as
Assignments prescribed format (Appendix-II)

Directorate of Online Education


APPENDIX-I
1. ARITHMETIC OPERATIONS

Aim
Develop python program to perform all the basic arithmetic operations.

Procedure

1. Start the program.


2. Read the values for the variables A and B.
3. Calculate the sum of A and B and Print the value.
4. Calculate the difference between A and B, and print the value
5. Calculate the product of A and B and print the value.
6. Calculate the Division of A by B and print the value.
7. Stop the program.

Program

A=int(input(“enter A Value”)
B=int(input(“enter b value”)
Print(“Addition:”,a+b)
Print(“Subtraction:”,a-b)
Print(“Multiplication:”,a*b)
Print(“Division:”,a/b)

Output

Enter the value of A : 10


Enter the value of B : 5

Addition 15
Subtraction 5
Multiplication 50
Division : 2

Result:
Thus the python program to perform the basic arithmetic operations has been completed
and executed successfully.

Directorate of Online Education


2. FIBONACCI SERIES

Aim
Develop python program to generate the Fibonacci series.

Procedure
1. Start the program.
2. Read the number of terms you want to print.
3. If the number of term is Zero, then print 0.
4. else
for(i=0;i<n;i++)
{
f=f+a;
a=b;
b=f;
}
5. Print the f value in every incrimination.
6. Stop the program.
Program

def fib(n):
a=0
b=1
if n == 1:
print(a)
else:
print(a)
print(b)
for i in range(2,n):
c=a+b
a=b
b=c
print(c)
fib(5
)

Output

01123

Result

Directorate of Online Education


Thus the Fibonacci series is generated successfully by using the python coding.

Directorate of Online Education


3. DEVELOP A PROGRAM FOR FINDING SUM OF NUMBERS

Aim

To develop a program finding sum of n numbers

Procedure

Step1: Get n value and assign s=0


Step 2: The loop start from i = 1 to n, calculate s=s+i until the
loop reach at n
Step 3: Display s value.

Program

def sum():
n= int(input(“enter n
values:”) s=0
for I in
range(1
,n+1):
s=s+i
print(“sum:”,s)
sum()
Output

Enter n values: 5
Sum:15

Result

Thus the program has been successfully completed.

Directorate of Online Education


4. STRING MANIPULATION

Aim

To manipulate the given string using built in function

Procedure

Step 1: Start the program.


Step 2: Read two strings S and S1.
Step 3: Manipulate the string using the following built in function
Step 4: Find length of the string using len(s) and print
Step 5: Find concatenate of two string – s+s1 and print
Step 6: Display 10 times of the string -10*s and print
Step 7: Find a particular letter from the string and print
Step 8: Count number of times the particular letter is
occurred using count() and print.
Step 9: Apply slicing operation s[3] and display
Step 10: Print s.replace(“Hello”,”hai”)

Step 11:Convert lower to upper – s.upper() and

print Step 12:Convert Upper to lower –s.lower() and

print Step 13: Stop the program

Program

S=”Hello”

Print(“length:”,len(s))

S1=”world”

Print(“concatenation:”,s+s1)

Print(“display multiple times:”,3 *s)

Print( s.find("H"))

Print( s.count('l'))

Print( s[3])

print (s.replace(“Hello”,”hai”))

print (s.upper())

print (s.lower())

Directorate of Online Education


Output

length : 5

concatenation: Hello world

display multiple times: Hello

Hello Hello

Hai

HAI

hai

Result

Thus the string manipulation concept is tested successfully.

Directorate of Online Education


5. CREATING AND MANIPULATING TUPLE

Aim

To create and manipulate Tuple operations

Program

# Create Tuple
tup=(21,36,14,25)

# Manipulate Tuple
>>print(tup[1])
Output:
36
>>tup[1]= 46
Tuple does not support to change the value

# Different ways of creating tuple


tup1 = (‘comp sc', ‘info practices', 2017, 2018)
tup2 = (5,11,22,44)
#covert list into tuple
L=[1,2,3]
T=tuple(L)
#adding two tuples
tup1 = (1, 2)
tup2 = ('a', 'b')
tup3 = tup1 +
tup2 print (tup3)
Output
(1,2,’a’,’b’)
# find the minimum value from a tuple
print(min(tup1))
Output
1
#find the maximum value from the tuple
print(max(tup1))

Result

Thus the tuple concept is tested successfully.

Directorate of Online Education


6. CREATING AND MANIPULATING DICTIONARY

Aim

To create and manipulate dictionary

Program
#create a dictionary
library = {‘Subject': ‘python', 'Rack': ‘11'}
# Display the Key values from Dictionary
>>>library.keys()
Subject rack
# Display the values from Dictionary
>>>library.values()
Python 11
# Modify the subject value
>>>library['Subject']='c++‘
>>>library.values
c++ 11
#Delete the Dictionary
>>>del library['rack'] # delete single element
>>>del library #delete whole dictionary
#pop() method is used to remove a particular item in a dictionary.
>>library.pop('rack')
#clear() method is used to remove all elements from the dictionary.
>>library.clear()

Result

Thus the create and manipulate Dictionary concept is tested successfully.

Directorate of Online Education


7. CREATING AND MANIPULATING LIST

Aim

To create and manipulate the list

Program
# Create a list
Nums=[80,60,70,75]
#display the list vale
>>>nums
[80,60,70,75]
# Append a single value into last
>>>nums.append(2)
[80,60,70,75,2]
#Append a single value in a particular position
>>>nums.append(1,3)
[80,3,60,70,75,2]
#Append a multiple values into last
>> l=[20,40]
>>nums.extend(l)
>>nums
[80,3,60,70,75,2,20,40]
# Delete a element from the list
>>>nums.remove(70)
>>> nums
[80,3,60, 75,2,20,40]
# Delete a element from the particular position
>>>nums.pop(1)
3 will be removed
If you have not specified the index value in pop.It removes from top
>>>nums.pop()
>>>nums
[80,60, 75,2,20]
# Modify the element from list in a particular position
>>>nums[1]=53
>>>nums
[80,53, 75,2,20]

Result

Thus the create and manipulate List concept is tested successfully.

Directorate of Online Education


8. FIND MEAN VALUE OF DATAFRAMES

Aim

To find mean value of dataframes

Procedure

Step 1: import the NumPy library

Step 2: create an array of values called data.

Step 3: use the np.mean() function to calculate the mean of the array, which is stored in the

variable mean.

Step 4: print the mean value to the console.

Program

import numpy as np

# create an array of values


data = np.array([10, 20, 30, 40, 50])

# calculate the mean of the


array mean = np.mean(data)

# print the mean


print("Mean: ", mean)

Output

Mean :30

Result

Thus the program has been completed successfully.

Directorate of Online Education


9. DATA AGGREGATION AND GROUPWISE OPERATIONS

Aim

To develop a program for Data Aggregation and group wise operations

Procedure

● A pivot table is a table that summarizes and aggregates data from a larger dataset based
on specific criteria.
● In Python, you can create pivot tables using the pandas library.
● To create a pivot table, you first need to import the pandas library using the command
import pandas as pd.
● Next, you can create a DataFrame object containing the data that you want to summarize.
● To create the pivot table, you can use the pivot_table() method of the DataFrame object.
● You need to specify the index column(s) and the column(s) to aggregate, as well as any
functions to apply to the data (such as sum, mean, or count).
● You can also specify additional columns to group by, which will create a multi-level
pivot table.
● Pivot tables can be used to summarize and analyze large datasets, allowing you to
quickly identify trends and patterns in the data.
● You can also use pivot tables to create charts and visualizations of the data.
● The resulting pivot table is a new DataFrame object that you can further manipulate and
analyze using the various methods and functions available in the pandas library.

Program

import pandas as pd

# create a DataFrame object containing the data


data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Emily'],
'Gender': ['Female', 'Male', 'Male', 'Male', 'Female'],
'Age': [25, 30, 35, 40, 45],
'Salary': [50000, 60000, 70000, 80000, 90000],
'Department': ['Sales', 'Marketing', 'Sales', 'Marketing', 'Sales']
}

df = pd.DataFrame(data)

# create a pivot table of the data


Directorate of Online Education
pivot = df.pivot_table(index=['Department', 'Gender'], values=['Salary', 'Age'],
aggfunc={'Salary': 'mean', 'Age': 'median'})

# print the pivot table


print(pivot)

Output

Department Gender Age Salary


Marketing Male 35 70000.000000
Sales Female 35 70000.000000
Sales Male 40 66666.666667

Result

Thus the program has been completed successfully.

Directorate of Online Education


10. BOX PLOTS UNDERSTANDING WITH EXAMPLE DATA

Aim

To Understand Boxplots with example data.

Procedure

Step1: import the necessary libraries and create an array of random values using the numpy
library.

Step2 : create a box plot of the data using the plt.boxplot() function

Step 3: set the title of the plot using plt.title().

Step 4 : show the plot using plt.show().

Step 5 : create box plots of multiple daptasets on the same plot by passing a list of arrays to the
plt.boxplot() function.

Step 6 : Additionally, you can customize the appearance of the plot, such as changing the color
or width of the box, by passing optional parameters to the plt.boxplot() function.

Program

import matplotlib.pyplot as
plt import numpy as np

# create an array of random values


data = np.random.normal(size=100)

# create a box plot of the data


plt.boxplot(data)

# set the title of the plot


plt.title("Box Plot Example")

# show the plot


Directorate of Online Education
plt.show()

Output

Result

Thus the program has been completed successfully.

11.IMPLEMENT TEXT FILE OPERATIONS


Directorate of Online Education
Aim

To implement text file operations

Procedure

1.Create()

Create a new file sample.txt

2.Write1()

Open a file with write mode


Read a content from keyboard
Write a content into file sample.txt
Close the file

3.Read1()

Open a file with read mode


Read a content from file sample.txt
Write a content on screen
Close the file
Program

def create():

f=open(‘sample.txt’,’x’)
f.close()

def write1():

f=open(‘sample.txt’,’w’)
s=’ welcome to python’
f.write(s)
f.close()
def read1():

f=open(‘sample.txt’,’r’)
s=f.read()
print(s)
f.close()
create()
write1()
Directorate of Online Education
read1()

Output

Welcome to python

Result

Thus the program has been completed

Directorate of Online Education


APPENDIX-II

LIST OF EXPERIMENTS -ASSIGNMENTS -LMS


Assignment Title of Program
No
1 Develop to find the area of a triangle
2 Convert Upper case to lower case
3 Develop a program for finding factorial of given numbers
4 Develop a program for finding sum of even numbers
5 Develop a program for finding sum of odd numbers
6 Develop a program for finding mean value of given data frame
7 Implement class and methods
8 Implement text file
9 Data visualizations for the dataset using heatmap
10 Develop a program for merging two dataset

Directorate of Online Education


Directorate of Online Education

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy