Podcast
Questions and Answers
What is the primary purpose of a software library in Python?
What is the primary purpose of a software library in Python?
What are the two ways to import a Python library?
What are the two ways to import a Python library?
What is the primary use of the NumPy library in Python?
What is the primary use of the NumPy library in Python?
What is the purpose of the np.reshape function in NumPy?
What is the purpose of the np.reshape function in NumPy?
Signup and view all the answers
What is the dimension of a 2D NumPy array?
What is the dimension of a 2D NumPy array?
Signup and view all the answers
What will happen if you try to reshape a 12-element 1D array into a 4x4 2D array?
What will happen if you try to reshape a 12-element 1D array into a 4x4 2D array?
Signup and view all the answers
What is the method to display the first and last 5 rows of a DataFrame?
What is the method to display the first and last 5 rows of a DataFrame?
Signup and view all the answers
How can you create a DataFrame from a csv file?
How can you create a DataFrame from a csv file?
Signup and view all the answers
What is the attribute of an Iris flower characterized by the length in centimeters?
What is the attribute of an Iris flower characterized by the length in centimeters?
Signup and view all the answers
How can you save a DataFrame to a csv file?
How can you save a DataFrame to a csv file?
Signup and view all the answers
How many Iris species are in the Iris sample data?
How many Iris species are in the Iris sample data?
Signup and view all the answers
What is the main library used for dealing with numeric and string data?
What is the main library used for dealing with numeric and string data?
Signup and view all the answers
What is the purpose of the 'describe' function in Pandas Series?
What is the purpose of the 'describe' function in Pandas Series?
Signup and view all the answers
What is the default name of the first column in a Pandas Series?
What is the default name of the first column in a Pandas Series?
Signup and view all the answers
How can you access a value in a Pandas Series using a custom index?
How can you access a value in a Pandas Series using a custom index?
Signup and view all the answers
What is the purpose of the 'read_csv' function in Pandas?
What is the purpose of the 'read_csv' function in Pandas?
Signup and view all the answers
What is a Pandas DataFrame?
What is a Pandas DataFrame?
Signup and view all the answers
What is the purpose of the np.transpose function in NumPy?
What is the purpose of the np.transpose function in NumPy?
Signup and view all the answers
What is the output of np.sort(arr_2D,axis=1)?
What is the output of np.sort(arr_2D,axis=1)?
Signup and view all the answers
What does np.sum(grades,axis=1) calculate?
What does np.sum(grades,axis=1) calculate?
Signup and view all the answers
What does grades[0,0] access in the array?
What does grades[0,0] access in the array?
Signup and view all the answers
What does grades[0:2] access in the array?
What does grades[0:2] access in the array?
Signup and view all the answers
What does grades[:,0] access in the array?
What does grades[:,0] access in the array?
Signup and view all the answers
What does grades[:,-1] access in the array?
What does grades[:,-1] access in the array?
Signup and view all the answers
What is the purpose of the reshape function in NumPy?
What is the purpose of the reshape function in NumPy?
Signup and view all the answers
What is the output of np.min(grades,axis=1)?
What is the output of np.min(grades,axis=1)?
Signup and view all the answers
What is the main difference between NumPy arrays and Pandas Series/DataFrames?
What is the main difference between NumPy arrays and Pandas Series/DataFrames?
Signup and view all the answers
In DataFrames, which statistics are calculated by column?
In DataFrames, which statistics are calculated by column?
Signup and view all the answers
What is the purpose of the describe()
function?
What is the purpose of the describe()
function?
Signup and view all the answers
How can you calculate the mean of a DataFrame?
How can you calculate the mean of a DataFrame?
Signup and view all the answers
What is the output of data.to_numpy()
?
What is the output of data.to_numpy()
?
Signup and view all the answers
How can you convert a NumPy array into a DataFrame?
How can you convert a NumPy array into a DataFrame?
Signup and view all the answers
What is the purpose of the iloc[]
function?
What is the purpose of the iloc[]
function?
Signup and view all the answers
What is the output of data.iloc[:, 0:4].to_numpy()
?
What is the output of data.iloc[:, 0:4].to_numpy()
?
Signup and view all the answers
What is the purpose of the head()
function?
What is the purpose of the head()
function?
Signup and view all the answers
How can you add columns to a DataFrame?
How can you add columns to a DataFrame?
Signup and view all the answers
What is the purpose of the std()
function?
What is the purpose of the std()
function?
Signup and view all the answers
Study Notes
NumPy Array
- Importing NumPy:
import numpy as np
- Creating a 1D array:
arr = np.array([1,2,3,4,5,6,7,8,9,10,11,12])
- Reshaping a 1D array into a 2D array:
arr_2D = arr.reshape(4,3)
Transposing NumPy Arrays
- Transposing a 2D array:
arr_2D_transposed = np.transpose(arr_2D)
NumPy Sorting
- Sorting a 2D array:
np.sort(arr_2D, axis=None)
(sorts the whole array) - Row-wise sorting:
np.sort(arr_2D, axis=1)
- Column-wise sorting:
np.sort(arr_2D, axis=0)
NumPy Calculation Functions
- Summation:
- Row-wise:
grades.sum(axis=1)
- Column-wise:
grades.sum(axis=0)
- All grades:
grades.sum(axis=None)
- Row-wise:
- Minimum:
- Row-wise:
grades.min(axis=1)
- Column-wise:
grades.min(axis=0)
- All grades:
grades.min(axis=None)
- Row-wise:
Indexing and Slicing
- Accessing individual elements:
grades[row index, col index]
- Selecting one row:
grades[row index]
- Selecting multiple rows:
grades[row index from : row index to]
- Selecting a subset of columns:
grades[:,0]
(selects all rows, column 0) - Selecting a subset of columns:
grades[:, 0:2]
(selects all rows, columns 0, 1) - Negative indices:
grades[:, -1]
(accesses the last column)
Pandas: Series and DataFrames
- Creating a Series:
grades = pd.Series([87, 100, 94])
- Creating a DataFrame:
grades = pd.DataFrame([87, 100, 94], index=['First', 'Second', 'final'])
- Accessing Series using string indices:
grades['First']
DataFrames
- Creating a DataFrame from a file:
myDataFrame = pd.read_csv("myfile.csv")
- Displaying the first and last 5 rows:
myDataFrame.head()
andmyDataFrame.tail()
- Statistics:
- Mean, min, max, std, var:
data.describe()
- Count, mean, min, max, std:
data.mean()
,data.min()
,data.max()
,data.std()
- Mean, min, max, std, var:
DataFrames and NumPy
- Converting a DataFrame to a NumPy array:
numpy_from_dataFrame = data.to_numpy()
- Converting a NumPy array to a DataFrame:
dataFrame_from_numpy = pd.DataFrame(numpy_from_dataFrame, columns = […])
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about popular Python libraries, including Numpy and Pandas, and how they can be used to improve your programming experience. This quiz covers the basics of Python libraries and their applications.