You are on page 1of 7

GOVERNMENT ENGINEERING COLLEGE MODASA (16)

COMPUTER ENGINEERING DEPARTMENT


PYTHON FOR DATA SCIENCE (3150713)
5TH CE (2020-2021)

PRACTICAL LIST

PRACTICAL - 1

1. Find the largest number from 3 numbers and print on the screen.
2. Take 3 variables and assign random numbers and display it. (using random package)
3. Take 3 variables and assign int and float values to it. Display 1st variable int value, 2nd
variable float value and 3rd variable complex value. (X = 20.5, Y = 20+5j, Z = 20)
4. Find mistake/s in program:

Case 1. 2my-first_name = "John"

print(2my-first_name)

Case 2. my-first_name = "John"

last-name=float(my-first_name)

Print(last-name)

PRACTICAL - 2

a = "Hello, World! "

age = 36

txt = "My name is John, and I am"

1. Print value of a.
2. Print first character.
3. Print 2nd to 5th character.
4. Remove extra space at last.
5. Find length of a string.
6. Convert all letters into lower case.
7. Convert all letters into upper case.
8. Using age and txt, display “My name is John, and I am 36 years old.”
9. Use following methods for your knowledge:

capitalize() Converts the first character to uppercase


casefold() Converts string into lowercase

center() Returns a centered string

count() Returns the number of times a specified value occurs in a string

endswith() Returns true if the string ends with the specified value

find() Searches the string for a specified value and returns the position of
where it was found

format() Formats specified values in a string

index() Searches the string for a specified value and returns the position of
where it was found

isdecimal() Returns True if all characters in the string are decimals

isdigit() Returns True if all characters in the string are digits

islower() Returns True if all characters in the string are lower case

isnumeric() Returns True if all characters in the string are numeric

isspace() Returns True if all characters in the string are whitespaces

istitle() Returns True if the string follows the rules of a title

isupper() Returns True if all characters in the string are upper case
join() Joins the elements of an iterable to the end of the string

ljust() Returns a left justified version of the string

lower() Converts a string into lower case

lstrip() Returns a left trim version of the string

replace() Returns a string where a specified value is replaced with a


specified value

rfind() Searches the string for a specified value and returns the last
position of where it was found

rindex() Searches the string for a specified value and returns the last
position of where it was found

rjust() Returns a right justified version of the string

rpartition() Returns a tuple where the string is parted into three parts

rsplit() Splits the string at the specified separator, and returns a list

rstrip() Returns a right trim version of the string

split() Splits the string at the specified separator, and returns a list

splitlines() Splits the string at line breaks and returns a list


startswith() Returns true if the string starts with the specified value

strip() Returns a trimmed version of the string

swapcase() Swaps cases, lower case becomes upper case and vice versa

title() Converts the first character of each word to uppercase

upper() Converts a string into upper case

zfill() Fills the string with a specified number of 0 values at the beginning

PRACTICAL - 3

Data Type: List

my_List = [3, 8, 1, 6, 0, 8, 4]

1. Make a list of above integer numbers.


2. Display all elements.
3. Perform addition of all members of the list. (Using direct function and without using direct
function)
4. Print all elements in reverse. (Using direct function and without using direct function)
5. Remove a particular number from the list. (Example No: 45 – must be present in your
list)
6. Write a Python program to get the largest number from a list.
7. Write a Python program to remove duplicates from a list.
8. Sort items in a list in ascending order. (Using direct function and without using direct
function)

Data Type: Tuple

my_Tuple = (3, 8, 1, 6, 0, 8, 4)

1. Print all elements of tuple.


2. Write a Python program to find the length of a tuple.
3. Write a Python program to check whether an element exists within a tuple.
4. Write a Python program to remove an item from a tuple.
5. Write a Python program to find the index of an item of a tuple.
6. Write a Python program to find the repeated items of a tuple.

Data Type: Set


my_Set = {3, 8, 1, 6, 0, 8, 4}

1. Write a Python program to create a set.


2. Display all elements.
3. Write a Python program to add member(s) in a set.
4. Write a Python program to remove item(s) from set.
5. Write a Python program to remove an item from a set if it is present in the set. If not
present then no error should be generated.

Data Type: Dictionaries

thisdict = {

"brand": "Ford",

"model": "Mustang",

"year": 1964

1. Print Key and value. (Individually and combined)


2. Write a Python script to check whether a given key already exists in a dictionary.
3. Write a Python script to add a key and value to a dictionary. Sample Dictionary : {0: 10,
1: 20} Expected Result : {0: 10, 1: 20, 2: 30}
4. Write a Python script to concatenate following dictionaries to create a new one.

Sample Dictionary: dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60}

Expected Result: {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

PRACTICAL - 4

1. Create a text(.txt) file which stores student‟s enrollment no. and name in a table
structure. Read the data from a text file and perform the random sampling on the data.
2. Create a CSV file which stores Student‟s Enrollment No, Name, Semester, Department,
Email, Mobile, Age (File should contain at least 30 records). Read the data from a file
using pandas library and print it.
3. Load image from file into memory using Scikit-image library. Print shape and size of the
image. Resize the image as per your requirement. Plot both the images using matplotlib
library.

PRACTICAL - 5

1. Create a Dataframe object using a list and dictionary which stores student data of your
class. Show how to access specific rows and columns from it.
2. Create an XML file which stores student‟s data. Parse data from a file and create a
dataframe object of it. Find duplicate values in a dataframe and remove all duplicate
values.
3. Create a Dataframe object of car data which includes columns like car model, brand,
color, manufacturing year, transmission type, car type(Sedan,Hatchback,SUV,Mini
SUV,Convertible). Create a categorical variable for car type which includes categories
(Sedan,Hatchback,SUV). Find the records in the data frame which are not in the range
of defined categories.
4. Using datetime module, print current date in „Mon, 31 August 2020‟ format. Add 5 hour
and 30 min in current date time and print new datetime. Count your exact age using
birthdate and current datetime.
5. Show how an Imputer module can be useful to deal with missing values.

PRACTICAL - 6

1. Draw a PIE chart which displays the number of laptops from different companies used
by the students in your class. Use appropriate colors and labels. Use following data:

Dell HP Acer Apple Lenovo

20 15 7 5 10

2. Variable A is the temperature of a reaction after 15 minutes. Variable B measures the


color of the product. You suspect higher temperature makes the product darker. Plot
temperature and color on a scatter diagram.
3. Plot the following coordinates in a geographical map.
Ahmedabad = (23.033863, 72.585022)
Surat = (22.310696, 73.192635)
Rajkot = (21.170240, 72.831062)
Bhavnagar = (22.308155, 70.800705)
Mumbai = (19.076090, 72.877426)
4. Show how directed and undirected graphs can be plotted using suitable examples.

PRACTICAL - 7

1. String 1: “Python for Data Science”

String 2: “Python for Machine Learning”

Calculate future Vector using CountVectorizer() and HashingVectorizer(). Sample Output


of CountVectorizer(): S1: [1,1,1,1,0,0] and S2: [1,1,0,0,1,1]

Package: Sklearn.feature_extraction

2. For any loop, find time required to execute loop.


3. Take an empty list and add values up to 106 and then find time required to execute the
loop.
4. Find time required to calculate future vectors using CountVectorizer() and
HashingVectorizer().
5. Install memory_profiler package from the command line:

import sys

!{sys.executable} –m pip install memory_profiler

OR

ipython –m pip install psutil

ipython –m pip install memory_profiler

6. Find memory required to add 106 elements in the list.


7. Find memory required to calculate future vectors using CountVectorizer() and
HashingVectorizer().
8. Download iris.csv dataset from location: https://gist.github.com/netj/8836201

For above dataset find:

a. Mean
b. Median
c. Variance
d. Range
e. Quartile
f. Skewness
g. Kurtosis

You might also like