Practical Exercises: Chapter 2
Exercise 1: Working with NumPy Arrays
Task: Create a NumPy array with the values [10, 20, 30, 40, 50]. Reshape it into a 2x3 array and calculate the sum of all elements.
Solution:
array = np.array([10, 20, 30, 40, 50, 60])
# Reshape the array into 2x3
reshaped_array = array.reshape(2, 3)
# Calculate the sum of all elements
total_sum = np.sum(reshaped_array)
print("Reshaped Array:\\\\n", reshaped_array)
print("Total Sum:", total_sum)
Exercise 2: Basic Data Manipulation with Pandas
Task: Create a Pandas DataFrame with the following data:
Then: ...