Tba Record Final
Tba Record Final
Register No :
Place: Kalavakkam
Date:
Examiner I Examiner II
CONTENTS
EX NO. Particulars PAGE NO. SIGN
Aim: To understand the types of variables, Functions, Arithmetic Operations, Types of data
Structures, Conditional statements and Loops
4
5
6
7
8
9
10
11
12
13
14
15
UNIT – 2 BASIC PYTHON LIBRARIES
Aim: To get introduced to NumPy and Pandas, Series & DataFrame,Reindexing, Indexing, Selection, Filtering,
Sorting, Unique Values and Value Counts.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
UNIT – 3 PYTHON FOR DATA PREPARATION
Aim: To learn about Handling Missing Data, Replacing Values, Removing Duplicates, Outlier treatment
Scaling and Encoding of the categorical data.
33
34
35
36
37
38
39
40
41
42
43
44
45
UNIT – 4 PYTHON FOR VISUALIZATION
Aim: To get introduced to Descriptive statistics, Matplotlib, Plotting Functions, Plotting with seaborn,
Box Plot, Histogram, Count Plot, Pie Chart, Violin Plot, Line Plot, Scatter Plot, Facet Grids, Heat Map,
Pair Plot.
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
UNIT – 5 PYTHON FOR MODEL BUILDING
Aim: To get introduced to SciPy, Clustering, statsmodels, Linear Regression, scikit-learn , Logistic
regression and Model Performance Measures
75
76
77
78
MULTIPLE LINEAR REGRESSION:
Problem Statement
Airbnb Inc is an online marketplace for arranging or offering lodging, primarily homestays, or tourism
experiences. Airbnb has close to 150 million customers across the world. Price is the most important factor
considered by the customer while making booking into a property. Strategic pricing of the properties is
important to avoid losing customers to the competitors.
We have data of 74111 Airbnb properties across the nations. Based on this data build a simple and multiple
linear regression model to predict the strategic pricing of a new listed property on Airbnb.
79
80
81
82
83
84
85
86
87
88
Conclusion
When accommodations increase by 1 unit, log_price increases by 0.1 units, keeping all other predictors constant ,When
no. of bathrooms increases by 1 unit, log_price increases by 0.18 units, keeping all other predictors constant ,etc....
There are also some negative coefficient values, for instance, room_type_shared_room has its corresponding co-efficient
as -1.08. This implies, when the room type is a shared room, the log_price decreases by 1.08 units, keeping all other
predictors constant. etc..
Insights
1) There is a Decrement in Price of the property by a larger factor if the rooms are shared rather than private.
2) There is a Decrement in Price of the property by a larger factor if the property has a Strict Cancellation Policy rather
than a Moderate Cancellation Policy.
3) More the number of bedrooms/bathrooms the price of the property goes up a little
4) While the number of beds increases, the price of the property goes down a little.
90
K-MEANS CLUSTERING :
91
92
93
94
95
96
97
98
HIERARCHICAL CLUSTERING:
99
100
101
102
103
104
LAB EXERCISES
LAB EXERCISE 1
Aim:
A mobile store MobiWorld sells different mobile phones to customers. For each order that is placed, the
store keeps a record of various attributes related to the mobile, like Price, Brand, RAM (GB), and Internal
Storage (GB).
First, we have to store our data to a variable that can be used to extract the stored information later. Let's
take an example of how we can do that in Python.
Output:
Q1. Suppose the store sold an Apple iPhone (4GB, 128GB) for $900. Store this information in the
variables price, brand, ram, and storage.
Q2. Let's say the store wants to save the information on the billing status of the above phone in a boolean
variable. Write the code in Python to implement the same
Q3. Check the data type of the variables price, brand, ram, and storage
Q4. Let's say a customer buys two Apple iPhones (4GB, 128GB) at a price of $900 each. What will be the
total bill that the customer has to pay?
105
Q5. Let's say the store provides a discount of 15𝑑𝑜𝑙𝑙𝑎𝑟𝑠𝑜𝑛𝑡ℎ𝑒𝐴𝑝𝑝𝑙𝑒𝑖𝑃ℎ𝑜𝑛(4𝐺𝐵,128𝐺𝐵)𝑡ℎ𝑎𝑡𝑐𝑜𝑠𝑡𝑠 900.
What will be the price of the iPhone after the discount?
Q6. Let's say a customer buys two Apple iPhones (4GB, 128GB) and pays a total bill of $1800. Write the
Python code to find the price of an Apple iPhone.
Q7. Let's say a customer buys x numbers of Apple iPhones (4GB, 128GB) for 900, so how many units
will be purchased for 3600. Write the Python code to find the value of x.
Q8. Suppose the store plans to provide a 4.5% discount on the Apple iPhone. What will be the discounted
price of the mobile?
106
Q9. print('The discounted price of the iPhone is ' + (discounted_price)) # What is the error?
Q10. To Add the variables brand, ram, and storage, What converstion can be used ? Why not the other?
107
LAB EXERCISE 2
Output:
brand_list
Q2. Create a list 'brand_list' and store the brand names in it.
brand_list=['Apple','Samsung','LG','Apple']
type(brand_list[0])
[out] str
Q4. Create lists for other attributes 'ram_list', 'storage_list' and 'price_list'.
ram_list=[4,12,8,8]
storage_list=[128,128,64,128]
price_list=[900,899,600,1000]
108
[out]BRAND LIST IS ['Apple', 'Samsung', 'LG', 'Apple']
RAM LIST IS [4, 12, 8, 8]
STORAGE LIST IS [128, 128, 64, 128]
PRICE LIST IS [900, 899, 600, 1000]
ram_count=len(ram_list)
ram_count
[out] 4
Q7. Find the minimum and maximum price among the mobile phones sold by the store. Print the output as
' The minimum price is $ followed by the value.
Q9. Print the first three items from the list price_list.
[out] The first three items from the list price_list are 900 , 899 , 600
print('The last but one item in the list brand_list is', brand_list[-2])
[out] The last but one item in the list brand_list is LG
109
Q12. Remove the last element from the list brand_list. Check whether the last element have been
removed.
brand_list.pop()
'Apple'
[out] brand_list
['Apple', 'Samsung', 'LG']
brand_list.append('Motorola')
brand_list
[out] ['Apple', 'Samsung', 'LG', 'Motorola']
index=brand_list.index('LG')
brand_list[index]='LG_1'
brand_list
[out] ['Apple', 'Samsung', 'LG_1', 'Motorola']
Q16. Remove the LG_1 that is after Samsung and print the brand_list.
brand_list.pop(2)
'LG_1'
print(brand_list)
[out] ['Apple', 'Samsung', 'Motorola']
storage=(128,128,64,128)
storage
110
[out] (128, 128, 64, 128)
type(storage)
[out] tuple
Q20. Store the details of a phone Brand- Apple, RAM( in GB) - 4GB, Storage (in GB)- 128GB, Price(in
$) : 800 in a single variable. Name the variable as 'attributes' Print the variable.
attributes={'Brand':'Apple' ,
'RAM':'4 GB' ,
'Storage':'128 GB' ,
'Price':'$800'}
attributes
[out] {'Brand': 'Apple', 'RAM': '4 GB', 'Storage': '128 GB', 'Price': '$800'}
type(attributes)
[out] dict
attributes['Price']
[out] '$800'
attributes['Price']='$900'
attributes
[out] {'Brand': 'Apple', 'RAM': '4 GB', 'Storage': '128 GB', 'Price': '$900'}
Q24. Create a dictionary 'products' for storing the attributes of 4 different mobile phones.
products={'brand':['Apple','Samsung','LG','Apple'] ,
'ram':[4,12,8,8] ,
'storage':[128,128,64,128] ,
111
'price':[900,899,600,1000]}
products
[out] {'brand': ['Apple', 'Samsung', 'LG', 'Apple'],
'ram': [4, 12, 8, 8],
'storage': [128, 128, 64, 128],
'price': [900, 899, 600, 1000]}
Q25. Extract the keys and values from the dictionary products. Print it with respective statements.
keys=products.keys()
print('The keys from the dictionary products: ',keys)
values=products.values()
print('The values from the dictionary products: ',values)
[out] The keys from the dictionary products: dict_keys(['brand', 'ram', 'storage', 'price'])
The values from the dictionary products: dict_values([['Apple', 'Samsung', 'LG', 'Apple'], [4, 12, 8, 8],
[128, 128, 64, 128], [900, 899, 600, 1000]])
112
LAB EXERCISE 3
Aim:
To exercise on the concepts of loops with python using the following practice questions.
Output:
Q1. Get input of a number, identity whether it is odd or even and present the result. Use an if else loop.
Q2. Explore the 'elif' loop. Get input of two numbers and operation to be done. consider the four operations
addition,subtraction, multiplication and division only. Print the output. If other operations are given, display the
output as invalid opr.
Q3. Suppose a customer is planning to buy a mobile phone but has a limited budget. Thus, his decision to buy
is based on the condition that the price comes under his budget. Let's say his budget is $600.
Write a code in Python that prints whether the customer can buy the iPhone or not based on his budget.
113
:
Enter your budget(in dollars): 800
Congrats! You can buy the Iphone.
114
LAB EXERCISE 4
Aim:
To practice with numpy packages by working with dictionaries,arrays,matrices etc in python using the
given questions.
Output:
Q1. Create a dictionary of 10 random values and demonstrate its type with required function
115
Q5. Create one dimensional vertical vector with 5 dimiesion
116
Q8.find the type of matrix created in Q6
117
Q14. Find how many unique values are there in a vector created with a,e,i,o,u,a,b,e
118
LAB EXERCISE 5
Q1. Create a series 'sports1'using pandas with values as 1,2,3,4 and index as Cricket, football, basketball
and Golf.
Q3. create another series 'sports2' with Cricket, Football, Baseball and Golf as index and 1,2,5,4 as values
119
Q7. Find the sum of sports1 and sports2 and store it as 'sports' and display it
Q9. Create a data frame of 10 rows and 5 columns with row index as alphabets from A to J and Column
index as Score1 to Score5. For values create random number between 0 and 1 and the output that you
produce must be fixed Hint: Explore method to fix the random no
np.random.seed(42)
df = pd.DataFrame(np.random.uniform(0,1,size=(10,5)),
columns=['Score1','Score2','Score3','Score4','Score5'],index=['A','B','C','D','E','F','G','H','I','J'])
df
120
Q10. Reset the row index from A to J to the default index that is 0,1…
121
Q12. If the answer is No for question 11 make the indexing change permenant in dataframe
122
Q13. Create a list as 'new' with cnt1, cnt2, cnt3 to cnt10 as elements.
Q14. Add the list 'new' as last column, index the column as 'Countries' in the dataframe.
123
LAB EXERCISE 6 & 7
Dataframe functions
Context: Starting in 2008, every year Forbes Magazine publishes a list of America's best colleges.
When it comes to the question everyone seems to be asking, “Is college worth it? this published list of
colleges comes handy to take a decision based on student's requirement or desire. The mission of the
college ranking by Forbes Magazine is to conduct an annual review of the undergraduate institutions
that deliver the top academics, best experiences, career success and lowest debt. Whether a school is
in the Top 10 or near the bottom of the list, the 650 colleges are the best in the country.
For most families, choosing a four-year college is one of the biggest and most expensive decisions
they can make. For students, this time of their life may layout their future plans. So choose carefully.
Data set 'ForbesAmericasTopColleges2019.csv'
About Data The data set contains the rankings of 650 Unites States colleges along with various other
statistics pertaining to each school.
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140