0% found this document useful (0 votes)
3 views

Python for Data Science

The document covers a Python for Data Science course, highlighting key libraries such as Pandas and Numpy. It includes examples of calculating variance, creating and manipulating Numpy arrays, and reshaping data. Additionally, it features quizzes and classwork related to indexing, slicing, and array operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python for Data Science

The document covers a Python for Data Science course, highlighting key libraries such as Pandas and Numpy. It includes examples of calculating variance, creating and manipulating Numpy arrays, and reshaping data. Additionally, it features quizzes and classwork related to indexing, slicing, and array operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Python for Data

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

You might also like