[go: up one dir, main page]

0% found this document useful (0 votes)
31 views75 pages

Chapter Quizzes - Part I

Uploaded by

Đỗ Anh
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)
31 views75 pages

Chapter Quizzes - Part I

Uploaded by

Đỗ Anh
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/ 75

Mai Cao Lan, Ph.D.

(USQ, Australia)
Dept. of Drilling & Production Engineering
Faculty of Geology & Petroleum Engineering
HCMUT, VIETNAM
10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 2
Mathematics in Data Science

Quiz: Which of the following statements is not true


concerning the mathematics contribution in Data
Science?

A. Linear Algebra

B. Multivariate Calculus

C. Fuzzy Logic

D. Deep Learning
10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 3
Data Analytics vs Data Analysis
Quiz: Fill in the blanks with appropriate answers

Feature Data Analysis Data Analytics

• Objective ? ?

• Outcomes/Results ? ?

• Methodology ? ?

• Tools ? ?

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 4
10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 5
Quiz: Which ones are correct?
1
if 5 > 2:
print("Five is greater than two!")

2
if 5 > 2:
print("Five is greater than two!")

3
if 5 > 2:
print("Five is greater than two!")
if 5 > 2:
print("Five is greater than two!")

4
if 5 > 2:
print("Five is greater than two!")
print("Five is greater than two!")

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 6
Python Arithmetic Operators

Quiz 1 Quiz 2 Quiz 3


x = 5 x = 5 x = 2
y = 2 y = 2 y = 3
print(x // y) print(x % y) print(x ** y)
>>> >>> >>>
??? ??? ???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 7
Python Arithmetic Operators
Active learning with application in mind

Quiz 1 Quiz 2
x = 5 x = 5
y = 2 y = 2
print(x % y) print(x // y)
>>> >>>
??? ???

1. When do we use the operator %?

2. For which cases do we need to use the operator //?

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 8
Python Assignment Operators
Quiz 1 Quiz 2
x = 5 x = 5
x += 3 x -= 3
print(x) print(x)
>>> >>>
??? ???

Quiz 3 Quiz 4
x = 5 x = 5
x *= 3 x /= 2
print(x) print(x)
>>> >>>
??? ???

When do we use these operators +=, -=, *=, /=?

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 9
Python Comparison Operators
Quiz 1 Quiz 2
x = 5 x = 5
y = 3 y = 3
print(x == y) print(x != y)
>>> >>>
??? ???

Quiz 5 Quiz 6
x = 5 x = 5
y = 3 y = 3
print(x >= y) print(x <= y)
>>> >>>
??? ???

What are the result types from these operators?

How are these operators used in practice?

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 10
Python Logical Operators

Quiz 1 Quiz 2 Quiz 3


x = True x = True
x = True
y = False y = False
print(not x)
print(x and y) print(x or y)
>>> >>> >>>
??? ??? ???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 11
Python Bitwise Operators

Quiz 1 Quiz 2
x = 5 # 0101 x = 5 # 0101
y = 3 # 0011 y = 3 # 0011
print(x & y) print(x | y)
>>> >>>
??? ???

Quiz 4 Quiz 3
x = 5 # 0101
x = 5 # 0101
y = 3 # 0011
print(~x)
print(x ^ y)
>>> >>>
??? ???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 12
Python Bitwise Operators

Exercise:

We have two 6-digit LEDs named A and B. Add another LED


named C so that each digit of the LED C is ON if and only if just
one of the corresponding digits of A and B is ON.

A= 1 0 0 1

B= 0 0 1 1

C= ? ? ? ?

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 13
Output Variables
Common Escape Sequences:
\n Newline
\t Tab
\\ Backslash
\’ Single quote
\’’ Double quote
\uXXXX Unicode character

Quiz 1

print(???)

>>>
Your text here with special characters: \n, \t, etc...

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 14
Output Variables (cont’d)

Quiz 2
name = "Alice"
age = 30
print(???)
>>>
Name: Alice & Age: 30
Quiz 3

name = "Alice"
age = 30
print(???)

>>>
Alice’s age is 30

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 15
Slicing Strings in Python

Quiz
print(str1[1:3])
print(str1[-3:-1])
>>>
???
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 16
Slicing Strings in Python

Quiz 1
b = "Hello, World!"
print(b[2:5])
print(b[:5])
print(b[2:])
print(b[-5:-2])
>>>
???
???
???
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 17
for Loop in Python
Fill in the blanks to complete the loop that prints the results below

Quiz 1:

for ____ in []:


print()

>>>
1
4
9
16

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 18
Range with for Loops
Fill in the blanks to complete the loop that prints the results below

Quiz 2:

for i in range(__,__,__):
print(i)

>>>
0
-1
-2

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 19
while loop in Python
Quiz: Randomly guess a number until it matches a given one

import random as rd
given = 3
guess = rd.randint(0,9)
counter = 1
while ???:
print(f'not matched this time! guess= ???')
guess = ???
counter = ???
print(f"Bingo, matched after ??? trials (guess = ???)")

>>>
not matched this time! guess= 0
not matched this time! guess= 2
not matched this time! guess= 1
not matched this time! guess= 4
Bingo, matched after 5 trials! (guess = given = 3)

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 20
break statement in loops
Quiz

for i in range(10):
if i == 5:
break
print(i)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 21
continue statement in loops
Quiz

for num in range(6):


if num == 3:
continue
print(f"Number: {i}")

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 22
Nested loops

Quiz
for i in range(5):
for j in range(i+1):
print("1", end="")
print()
>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 23
List Slicing in Python

Quiz 1
fruits = ["apple", "banana", "orange", "grape", "kiwi"]
print(fruits[1:3])
print(fruits[2:])
print(fruits[:4])
print(fruits[::2])

>>>
???
???
???
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 24
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


fruits.append("grape")
print(fruits)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 25
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


# Add grape as the second item of the fruits list
fruits.____________
print(fruits)

>>>
["apple", "grape", "banana", "orange"]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 26
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


# Add "grape" and "kiwi" to the existing fruits list
fruits._______________
print(fruits)
>>>
["apple", "banana", "orange", "grape", "kiwi"]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 27
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


fruits.pop(1)
print(fruits)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 28
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


# Remove ‘banana’ from the fruits list
fruits._____
print(fruits)
>>>
["apple", "orange"]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 29
Using List’s Methods

Quiz 1

fruits = ["apple", "banana", "orange"]


# print the position of “orange” in the fruits list
print(???)

>>>
2

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 30
Using Built-In Functions for Lists

Quiz 1

numbers = [5, 3, 7, 1]
# Print the numbers in the ascending order
sorted_numbers = ???
print(sorted_numbers)
>>>
[1,3,5,7]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 31
Using Built-In Functions for Lists

Quiz 1

fruits = ["apple", "banana", "orange"]

# Print the total number of elements in the fruits list


print(???)
>>>
3

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 32
Using Built-In Functions for Lists

Quiz 1

numbers = [5, 3, 7, 1]
# print the location of the maximum number in the given list
print(???)

>>>
2

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 33
Using Built-In Functions for Lists

Quiz 1

numbers = [5, 3, 7, 1]
# print the sum of all numbers in the above list
print(???)

>>>
16

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 34
Using Built-In Functions for Lists

Quiz 1

numbers = [5, 3, 7, 1]
# print the list in ascending order
print(???)

>>>
[1, 3, 5, 7]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 35
Built-In Functions for Lists

Quiz 1

numbers = [5, 3, 7, 1]
reversed_nums = list(???)
print(reversed_nums)

>>>
[1, 7, 3, 5]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 36
Built-In Functions for Lists

Quiz 1
fruits = ["apple", "banana", "orange"]
# Print all items of the fruits list along with their ordinal
number
for ??? in ???:
print(???)
>>>
0 apple
1 banana
2 orange

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 37
Accessing Tuple Elements

Quiz 3

my_tuple = (5, 3, 2, 1, 8)

# print the first three elements of the tuple


print(____)

>>>
(5,3,2)

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 38
Concatenating Tuples

Quiz 1

tuple1 = ("a", "b" , "c")


tuple2 = (1, 2, 3)

tuple3 = tuple1 + tuple2


print(tuple3)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 39
Membership Testing for Tuples/Lists

Quiz 1

fruits = ("apple", "banana", "cherry", "grape")


# Checks if ‘banana’ exists in the fruits tuple
banana_in_fruits = ???
print(f'banana in fruits: {banana_in_fruits}')

>>>
banana in fruits: True

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 40
Tuple’s/List’s Methods
Quiz 1
my_tuple = (1, 2, 3, 1, 1, 4)
# Count the number of 1’s in the given tuple
print(???)

>>>
3

Quiz 2
my_tuple = (10, 20, 30, 40, 30)
# Find the position of number 30 (first encountered)
in the given tuple
print(???)
>>>
2

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 41
Duplicate Items in a Set?

Quiz 1
this_set = {"apple", "banana", "cherry", "apple"}

print(this_set)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 42
True, False vs 1, 0 in Sets

Quiz 1

this_set = {"apple", "banana", "cherry", True, 0, 1, 2}


print(len(this_set))
>>>
???
Quiz 2

this_set = {"apple", "banana", False, 0, 1}


print(len(this_set))
>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 43
Using Set’s Methods

Quiz 1
fruits = {"apple", "banana", "cherry"}
# Add "orange" to the fruits set
fruits._____
print(fruits)
>>>
{“apple”,”banana”,”cherry”,”orange”}

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 44
Using Set’s Methods

Quiz 1
fruits = {"apple", "banana", "cherry"}
# delete ‘banana’ from the fruits set
fruits._____
print(fruits)
>>>
{“apple”,”cherry”}

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 45
Using Set’s Methods
Quiz 1

set1 = {1, 2, 3}
set2 = {3, 4, 5}

# Union of set1 and set2 (elements in either set)


union = ???
#Intersection of set1 and set2 (elements in both sets)
intersection = ???
#Difference of set1 and set2 (elements in set1 but not in set2)
difference = ???
>>>
{1, 2, 3, 4, 5}
{3}
{1,2}

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 46
Using Dictionary’s Methods

Dictionary - Quiz 1
my_dict = {
"name": "Bob",
"age": 30
}
# Adding a key:value as “job”:“Engineer”
# and modifying “age” to 32
my_dict.______({"age": 32, "job": "Engineer"})
print(my_dict)
>>>
{'name': 'Bob', 'age': 32, 'job': 'Engineer'}

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 47
Using Dictionary’s Methods
Dictionary - Quiz 2

my_dict = {
"name": "Bob",
"age": 25,
"email": "bob@example.com",
"city": "New York",
"nationality": "U.S"
}
# delete the entry “email”
my_dict._______
print(my_dict)

>>>
{'name':'Bob','age':25,'city':'New York','nationality':'U.S'}
10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 48
Using Dictionary’s Methods
Print all key-value pairs
Dictionary - Quiz 3

my_dict = {
"name": "Bob",
"age": 25,
"city": "New York",
}

for ______ in my_dict.______:


print(f“__________")

>>>
name: Bob
age: 25
city: New York

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 49
Using Dictionary’s Methods
Quiz 1

my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York'}


print(my_dict.keys())

>>>
???

Quiz 2

my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York'}


print(my_dict.values())

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 50
Using Dictionary’s Methods
Quiz 1
my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York’}
# Change the age to 25
??? = 25
print(my_dict)

>>>
{'name': 'Alice', 'age': 25, 'city': 'New York’}

Quiz 2

my_dict = {'name': 'Alice', 'age': 25, 'city': 'New York'}


# Add a new entry (‘nationality’:’U.S.’) into the dictionary
??? = ‘U.S.’
print(my_dict)

>>>
{'name':’Alice','age':30,'city':'New York,’nationality’:’U.S.’}

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 51
Using Dictionary’s Methods

Quiz

my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York’}


age = my_dict.pop('age’)
print(my_dict)

>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 52
Using List Comprehension
Quiz 1
x = [1, 2, 3]
# print items in the list that is less than 4
lt_4 = [???]
print(lt_4)
>>>
[1,2,3]

Quiz 2
matrix = [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
# print the diagonal of the given matrix
diagonal = [???]
print(diagonal)
>>>
???

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 53
Using Set Comprehension
Quiz 2

original_set = {1, 2, 3, 4, 5}
# calculate cumulative sum of the items in the set
cumsum_set = {???}
print(cumsum_set)

>>>
[1,3,6,10,15]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 54
Python Functions
Quiz 1
def my_function(a, b=2):
return a * b

result = my_function(3)
print(result)
>>>
???

Quiz 2
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
results = factorial(5)
print(results)
>>>
???
10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 55
Lambda Functions

Quiz 1

temp_c = [0,10,30,50]
# Define lambda function to convert C-degree to F-degree temp.
c2f = lambda ???
# Calling the lambda function
temp_f = ???
print(temp_f)

>>>
[32.0,50.0,86.0,140.0]

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 56
10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 57
Creating and Manipulating Arrays in NumPy

Quizzes:

a) Create a NumPy array from the list [10, 20, 30, 40, 50].

b) Create a 4x4 array filled with zeros, and create a 3x3 array filled
with ones.

c) Create an array of even numbers from 0 to 20.

d) Create a 1D array of 12 elements and reshape it into a 3x4 array.

e) Given the 3x4 array from Quiz d), flatten it into a 1D array.

f) Create a 2D array of random numbers (5x5) and calculate the


mean of each column.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 58
Creating and Manipulating Arrays in NumPy

Quizzes:

g) Given: Array 1: [1, 2, 3, 4, 5], Array 2: [4, 5, 6, 7, 8]. Find the


common elements between two arrays.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 59
NumPy Array Operations

a) Given an 1D array representing the temperatures in Celsius


[0, 10, 20, 30, 60]. Write code to convert it to Fahrenheit
degree.

b) Given the exam scores [85, 92, 78, 95, 88, 72, 97, 65, 74, 83],
calculate the average score, the highest score, and the lowest
score?

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 60
NumPy Array Operations
Given a 2D array (3x4) representing matrix A (see below).
Calculate the sum of all elements in each columns and in each
rows in the matrix.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 61
Indexing and Slicing in NumPy

1. Given an array [1, 4, 8, 2, 9, 5, 7, 3, 6], how would you extract all


elements from the given array that are greater than 3?

2. Given a 2-dimensional array, how would you extract all


elements in

a. The third column?

b. The second row?

c. The block ([2, 2], [3, 9])

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 62
Linear Algebra with NumPy
1. Create two matrices A = [[1, 2], [3, 4]] and B = [[5, 6], [7, 8]].
Compute their matrix multiplication.

2. Transpose, inverse the matrix C, and calculate its determinant:

C = [[9, 5, 4, 7], [1, 4, 3, 1], [6, 8, 4, 0]]

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 63
Exercises with NumPy

1. Create a random 3D array with dimensions 3×4×5. Slice out


the second "plane" (2D slice) along the first axis.

2. Given a random 4x4 array of normal distribution, find all


elements that are greater than a threshold of 0.5.

3. Solve the following system of linear equations:

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 64
Pandas Series
Q1: Create a Pandas Series using the following data: [‘school',
‘college', ‘university’, ‘institute’]. Assign custom index labels as
follows: ['A', 'B', 'C', 'D'].

Q2: Temperature data are recorded during a week in degrees


Celsius. Create a Pandas Series using the dates as the index.
Then, find the maximum temperature recorded during the week
and display it.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 65
Pandas Series’ Methods
Quiz: Given a list of Celcius temperature data [0, 20, 30, 50]

- Create a Pandas series from the list of temperatures above

- Define a function that takes a Celsius temperature and


returns the equivalent Fahrenheit temperature using the
formula: F = (C*9/5)+32

- Use the apply() method of Pandas series to convert the


temperatures from Celsius to Fahrenheit degree using the
function above.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 66
Quiz: Creating a DataFrame from a
Dictionary
Quiz: Create a Pandas DataFrame from the given data.

Employee Data:

 Names: ['Alice', 'Bob', 'Charlie', 'David’]

 Ages: [25, 30, 35, 40]

 Cities: ['New York', 'Los Angeles', 'Chicago', 'Houston']

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 67
Quiz: Creating a DataFrame from a List
of Lists
Quiz: Create a Pandas DataFrame from the given data. Specify
appropriate column names: ['Product', 'Price', 'Category'].

Data:

 ['Laptop', 1200, 'Electronics’]

 ['Chair', 150, 'Furniture’]

 ['Book', 20, 'Stationery’]

 ['Pen', 2, 'Stationery']

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 68
Quiz: Creating a DataFrame from a
NumPy Array
Quiz: Create a Pandas DataFrame from the given data. Specify
appropriate column names: ['Celsius', 'City'].

Data:

 [0, 'New York’]

 [20, 'Los Angeles’]

 [37, 'Chicago’]

 [100, 'Houston']

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 69
Exercise: Creating Pandas DataFrame
1. Create a list of student IDs from 1 to 5.

2. Use the following lists of scores for each student:


Math Scores: [85, 90, 78, 92, 88]
Science Scores: [88, 95, 80, 85, 90]
English Scores: [75, 85, 70, 90, 82]

3. Use list comprehension to combine these scores into a


DataFrame where each row corresponds to a student, and each
column corresponds to a subject.

4. Use the student IDs as the index of the DataFrame, and the
subjects as the column names.

10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 70
Practical Exercise
The PVT fluid data from a gas well in the Anaconda Gas Field is given below:

The well is producing at a stabilized


p (psig) 𝝁 (cp) Z
0.0 0.01270 1.000 bottom-hole flowing pressure of 2800
400.0 0.01286 0.937 psi. The wellbore radius is 0.3 ft. The
800.0 0.01390 0.882
following additional data is available:
1200.0 0.01530 0.832
k=65 md; h=15 ft; T=600 °R; Pr = 4400
1600.0 0.01680 0.794
2000.0 0.01840 0.770 psi; re=1000 ft.
2400.0 0.02010 0.763
2800.0 0.02170 0.775
Calculate the gas flow rate in Mscf/day
3200.0 0.02340 0.797
using the formula in the next slide
3600.0 0.02500 0.827
4000.0 0.02660 0.860
4400.0 0.02831 0.896

10/26/2024 Dr. Mai Cao Lan, Dept. of Drilling & Production Engineering, GEOPET, HCMUT 71
Practical Exercise (cont’d)
The production flow rate of a gas well can be estimated using
well and reservoir data as follow:

qg 

kh m  p r   m  p w f 
  0.4 72 re  
14 24 T  ln   s
  rw  

where the real-gas pseudo pressure m(p) is defined as:

p 2p
m( p )   dp
0 Z
10/26/2024 Dr. Mai Cao Lan, Dept. of Drilling & Production Engineering, GEOPET, HCMUT 72
Practical Exercise (cont’d)
Trapezoidal Method

10/26/2024 Dr. Mai Cao Lan, Dept. of Drilling & Production Engineering, GEOPET, HCMUT 73
Practical Exercise (cont’d)

10/26/2024 Dr. Mai Cao Lân, Faculty of Geology & Petroleum Engineering, HCMUT, Vietnam 74
Matplotlib package
Exercise:

- Generate an array of 100 points ranging from 0 to 10 (inclusive)


using numpy.

- Calculate the following functions for each point:

+ Function 1: 1 = sin( )

+ Function 2: 2 = cos( )

+ Function 3: 3 = 2

- Create a line plot for each function using a different color and label
each line accordingly. Add a title, and labels for the x-axis and y-axis.
Include a legend to distinguish between the lines.
10/26/2024 Dr. Mai Cao Lan - Faculty of Geology & Petroleum Engineering, HCMUT 75

You might also like