Pandas_Numpy[1]
Pandas_Numpy[1]
Easy
Write a Python program to create a NumPy array with values ranging from 1 to 10.
o Input: None
o Output:
o array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Given the DataFrame below, write a Pandas program to select the Name column.
o Input:
Python
df = pd.DataFrame({
})
o Output:
o 0 Alice
o 1 Bob
Write a Python program to create a Pandas DataFrame from the dictionary below.
o Input:
Python
data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
o Output:
o A BC
o 0 1 4 7
o 1 2 5 8
o 2 3 6 9
Medium
o Input:
o Output:
o 30.0
Given the DataFrame below, write a Pandas program to filter rows where the Age is
greater than 30.
o Input:
Python
df = pd.DataFrame({
})
o Output:
o 2 Charlie 35 Chicago
Write a Python program to generate a 3x3 matrix of random values between 0 and 1
using NumPy.
o Input: None
o Output: (Values may vary)
Given the DataFrame below, write a Pandas program to calculate the sum of each
column.
o Input:
Python
df = pd.DataFrame({
'C': [7, 8, 9]
})
o Output:
o A 6
o B 15
o C 24
o dtype: int64
Write a Pandas program to replace missing values (NaN) in the DataFrame with the
mean of the respective column.
o Input:
Python
df = pd.DataFrame({
'C': [7, 8, 9]
})
o Output:
o A B C
o 0 1.0 4.0 7
o 1 2.0 5.0 8
o 2 3.0 4.5 9
Hard
Write a Python program to calculate the dot product of two NumPy arrays.
o Input:
Python
o Output:
o 32
Given the DataFrame below, write a Pandas program to group by the City column
and calculate the mean Age for each city.
• Input:
Python
df = pd.DataFrame({
})
• Output:
• Age
• City
• Chicago 35.0
Write a Python program to apply a custom function to the Age column of the
DataFrame below to convert the ages from years to months.
• Input:
Python
df = pd.DataFrame({
})
def years_to_months(age):
return age * 12
• Output:
• Name Age
• 0 Alice 300
• 1 Bob 360
• 2 Charlie 420
• Input:
Python
• Output:
• AB
• 0 1 3
• 1 2 4
• 0 5 7
• 1 6 8
Write a Python program to find the eigenvalues and eigenvectors of a 2x2 matrix
using NumPy.
• Input:
Python
• Output:
• Eigenvectors:
• [[ 0.894, -0.707],
• [ 0.447, 0.707]]
• Input:
Python
• Output:
• array([[1, 2, 3],
• [4, 5, 6],
• [7, 8, 9]])
Given the DataFrame below, write a Pandas program to pivot the DataFrame so that
the Name column becomes the index, and the Subject column values become
columns with the corresponding Score.
• Input:
Python
df = pd.DataFrame({
})
• Output:
• Math Science
• Name
• Alice 85 92
• Bob 78 81
This sheet covers fundamental and advanced topics in Pandas and NumPy,
enabling you to test a broad range of data manipulation and computational skills.