CS177-lecture-20220210

NumPy #

We can use NumPy with

import numpy as np

We can create new arrays with

a = np.array([1, 5, 7])

We can specify number of dimensions or data types:

b = np.array([1, 2, 3], ndim=2)
c = np.array([1, 2, 3, 4], dtype=complex)

We can see the shape of an array via

print(a)
print(a.shape)

You can set the shape of an array

d = np.array([1, 2, 3], [4, 5, 6])
d.shape = (3, 2)

To create an array in a range

a = np.arange(24)

We can reshape this new array:

image_2022-02-10-16-14-42

If we already have a Python list, we can create a NumPy array from it:

x = [1, 2, 3]
a = np.asarray(x)

image_2022-02-10-16-16-26 image_2022-02-10-16-18-43

Pandas #

  • High performance data manipulation and data analysis
  • DataFrame object, default and customized indexing
  • High efficient merging and joining of data
  • Columns from a data structure can be deleted or inserted
  • Label based slicing, indexing of large datasets

Structures #

  • Series, 1D labeled homogenous array
  • DataFrame, 2D labeled hetergenously typed columns
  • Panel, 3D labeled, size mutable array

image_2022-02-10-16-22-17 image_2022-02-10-16-24-24 image_2022-02-10-16-25-21 image_2022-02-10-16-27-17 image_2022-02-10-16-28-22 image_2022-02-10-16-29-29 image_2022-02-10-16-29-57 image_2022-02-10-16-30-55 image_2022-02-10-16-32-04

Plotting #

image_2022-02-10-16-33-14 image_2022-02-10-16-34-47 image_2022-02-10-16-34-57 image_2022-02-10-16-35-06 image_2022-02-10-16-35-24