0% found this document useful (0 votes)
13 views2 pages

Pandas NumPy Practice Questions

Uploaded by

OMKAR AGARWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Pandas NumPy Practice Questions

Uploaded by

OMKAR AGARWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Pandas and NumPy Exam Practice Questions

NumPy Practice Questions


1. Array Creation and Manipulation:
- Create a 3x3 array filled with random integers between 10 and 50.
- Replace all even numbers in the array with -1.
- Reshape the array into a 1D array.

2. Matrix Operations:
- Create two 3x3 matrices A and B using NumPy with random values between 1 and 10.
- Compute their matrix product A × B.
- Find the transpose of the result and its determinant.

3. Indexing and Slicing:


- Create a 5x5 matrix with values from 1 to 25.
- Extract the middle 3x3 submatrix.
- Set all values in the last column to 0.

4. Statistical Analysis:
- Create an array of 50 random numbers between 0 and 100.
- Find the mean, median, standard deviation, and variance of the array.
- Sort the array in descending order.

5. Broadcasting:
- Create a 3x3 matrix and a 3x1 column vector.
- Add the column vector to each row of the matrix using broadcasting.

Pandas Practice Questions


1. DataFrame Creation and Basic Operations:
- Create a DataFrame from the following dictionary:
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Age': [25, 30, 35, 40],
'Salary': [50000, 60000, 70000, 80000]
}
- Add a new column 'Tax' which is 10% of the Salary.
- Drop rows where the 'Age' is greater than 30.

2. Filtering and Indexing:


- Load a CSV file (or create one if not available) containing columns like Product, Price, and
Quantity.
- Filter all rows where Price > 100.
- Find the total quantity of all products with Price > 100.
3. Aggregation and Grouping:
- Create a DataFrame with columns ['Department', 'Employee', 'Salary'].
- Group the data by 'Department' and calculate the total salary for each department.
- Find the average salary of employees in each department.

4. Handling Missing Data:


- Create a DataFrame with some missing values:
df = pd.DataFrame({
'A': [1, 2, None, 4],
'B': [None, 2, 3, 4],
'C': [1, 2, 3, None]
})
- Fill missing values in column 'A' with the mean of that column.
- Drop rows where more than one value is missing.

5. Merging and Joining:


- Create two DataFrames:
df1 = pd.DataFrame({'ID': [1, 2, 3], 'Name': ['Alice', 'Bob', 'Charlie']})
df2 = pd.DataFrame({'ID': [1, 2, 4], 'Age': [25, 30, 35]})
- Merge them on 'ID' using an inner join.
- Perform a left join and explain the difference.

6. Time Series Analysis:


- Create a DataFrame with a 'Date' column containing dates from January 1, 2023, to
January 31, 2023.
- Add a column 'Sales' with random values.
- Find the total sales for the first week of January.

Combined NumPy and Pandas Questions


1. Data Transformation:
- Use NumPy to create an array of 100 random integers between 1 and 100.
- Convert it into a Pandas DataFrame with columns ['Value'].
- Add a new column 'Category' where:
- 'Low' if the value is < 30.
- 'Medium' if the value is between 30 and 70.
- 'High' if the value is > 70.

2. Statistical Analysis:
- Create a large DataFrame with 10,000 rows and 5 columns containing random integers.
- Use NumPy to compute the correlation matrix.
- Use Pandas to identify columns with the highest correlation.

3. Performance Comparison:
- Create a NumPy array and a Pandas DataFrame, both with 1,000,000 random values.
- Compare the time taken to compute the mean of both using NumPy and Pandas.

You might also like