Lab Manual - V20UDS401 Programming For Analytics
Lab Manual - V20UDS401 Programming For Analytics
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
3. To impart the concepts like Data Types, Looping, Statistics methods, Function
Files, Inheritance, Data Visualization, Data Aggregation and merging two datasets
COURSE OUTCOME
Aim
Develop python program to perform all the basic arithmetic operations.
Procedure
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
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.
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
Aim
Procedure
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
Aim
Procedure
Program
S=”Hello”
Print(“length:”,len(s))
S1=”world”
Print(“concatenation:”,s+s1)
Print( s.find("H"))
Print( s.count('l'))
Print( s[3])
print (s.replace(“Hello”,”hai”))
print (s.upper())
print (s.lower())
length : 5
Hello Hello
Hai
HAI
hai
Result
Aim
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
Result
Aim
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
Aim
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
Aim
Procedure
Step 3: use the np.mean() function to calculate the mean of the array, which is stored in the
variable mean.
Program
import numpy as np
Output
Mean :30
Result
Aim
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
df = pd.DataFrame(data)
Output
Result
Aim
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 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
Output
Result
Procedure
1.Create()
2.Write1()
3.Read1()
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