0% found this document useful (0 votes)
10 views6 pages

ANLY Aishwarya Assignment 3

Uploaded by

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

ANLY Aishwarya Assignment 3

Uploaded by

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

1

Assignment 3:
Advance programming inn Data Analytics
ANLY 560-90-0
Student: Aishwarya Reddy
2

What is the difference between Modules, Packages and Libraries in Python?

Module:

One Python file that includes variables, classes, and methods that can be imported and utilized

by other Python scripts is called a module. For instance, the module random.py has routines for

creating random integers.

Example:

math_utils.py

def add(a, b): return a + b

def subtract(a, b): return a - b

Package:

A group of many modules arranged in a directory with a __init__.py file is called a package. The

package may be seen as a module in and of itself thanks to the __init__.py file. For instance, the

package numpy includes several modules for numerical computation.

Example:

mypackage/

├── __init__.py

├── module1.py

├── module2.py
3

Libraries:

A library is an assortment of packages and modules that offer a variety of features. Libraries may

have several packages with different functions. For instance, the package Pandas contains

modules for both data analysis and manipulation.

Example: Popular Python libraries include matplotlib, pandas, and numpy.

Q2:
Python task
Write a Python script that imports the random module.
import random

random_value = random.random()
print(random_value)

Use the random.randint() function to generate and print 10 random integers between 1 and
100.

import random

for _ in range(10):
random_number = random.randint(1, 100)
print( random_number)
4

output:
66
53
33
23
33
49
78
24
70
80

Use the random.choice() function to randomly select an element from a list [‘apple’,

‘banana’, ‘cherry’, ‘date’, ‘elderberry’] and print the selected fruit.

import random
fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
selected_fruit = random.choice(fruits)
print(selected_fruit)

output:
apple
5

R Task:
1.
%load_ext rpy2.ipython
2.
##Install the package

%%R

install.packages("ggplot2")
3.
#2. Load the packages --> similar to the import statement in python
4.
#3. Use the functions and methods from the package as built-in functions
5.
%%R

str(quakes)
6.
# %% [code]
Installment of dplyr
7.
%%R
library(dplyr)
6

8.
%%R

data <- data.frame(


ID = 1:10,
Score = sample(50:100, 10, replace = TRUE)
)

sorted_data <- arrange(data, desc(Score))


print(sorted_data)

output:
ID Score
1 5 100
2 10 84
3 9 78
4 7 77
5 3 76
6 6 76
7 2 75
8 1 74
9 8 58
10 4 54

You might also like