Python for Data Science
Python for Data Science
science
Toyin Odutola
The material in this course was
screenshot from the Python for data
science course in solo learn
Which of the following is a python library used in
data science
a)Penguins
b)Pandas
c)bears
Vaccination project on variance
Quiz
Other solutions for variance
• vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ]
• #your code goes here
• mean = sum(vac_nums)/len(vac_nums)
• variance = sum((elem-mean)**2 for elem in
vac_nums)/len(vac_nums)
• print(variance)
Other solutions for variance
0.9875 answer
statistics
Numpy
7.1 Numpy Arrays
np.arange(2, 10, 3) - from 2 to 10 with step 3
2 < 10 2 + 3 = 5 < 10 5 + 3 = 8 < 10 8 + 3 = 11 > 10
That is why np.arange(2, 10, 3) = [2, 5, 8]
Example
• What will be the output ?
import numpy as np
x= np.arange(2,8,2)
print (x)
Output [2 4 6]
Example
• What will be the output ?
import numpy as np
x= np.arange(2,8,2)
x=np.append(x,x.size)
print (x)
Output [2 4 6 3]
Example
• What will be the output ?
import numpy as np
x= np.arange(2,8,2)
x=np.append(x,x.size)
x=np.sort(x)
print (x)
Output [2 3 4 6]
Example
• What will be the output ?
import numpy as np
x= np.arange(2,8,2)
x=np.append(x,x.size)
x=np.sort(x)
print (x[1])
Output 3
Fill in the blanks to reshape the array called "x" to 5 rows. "x"
contains 20 elements.
x. (5, )
flatten
Example
• What is the output of this code?
x = np.arange(1, 8, 3)
print(x)
[1 4 7]
Example
• What is the output of this code?
x = np.arange(1, 8, 3)
z = x.reshape(3, 1)
print(z)
[1]
[ 4]
[ 7]
Example
• What is the output of this code?
x = np.arange(1, 8, 3)
z = x.reshape(3, 1)
print(z)
[1]
[ 4]
[ 7]
Class work
Output is 4
Indexing and slicing
Class work