0% found this document useful (0 votes)
5 views8 pages

Answers Key

The document contains a series of correct answers and explanations related to Python programming, data handling, and visualization techniques. It includes topics such as built-in functions, data structures, handling missing values, and visualization methods. Additionally, it provides examples and evaluations of various programming concepts and tools used in data analysis.
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)
5 views8 pages

Answers Key

The document contains a series of correct answers and explanations related to Python programming, data handling, and visualization techniques. It includes topics such as built-in functions, data structures, handling missing values, and visualization methods. Additionally, it provides examples and evaluations of various programming concepts and tools used in data analysis.
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

Here are the correct answers with brief explanations:

1. c) 0
[Link]('c', 0) returns the default value 0 since key 'c' is not in the dictionary.
2. b) if
The if keyword is used for conditional branching in Python.
3. a) array()
NumPy uses array() to create arrays.
4. c) Dimensions of array
[Link] returns the dimensions (rows, columns, etc.) of the array.
5. d) drop_duplicates()
In Pandas, drop_duplicates() removes duplicate rows.
6. b) 1D labeled array
A Pandas Series is a one-dimensional labeled array.
7. c) Pickle
Pickle is a binary format used for efficient storage and serialization.
8. b) HTTP
Web APIs typically use the HTTP protocol.
9. d) Pivoting and reshaping
These techniques restructure datasets for reporting and analysis.
10. c) Complex relationships across multiple dimensions
Multi-level indexing helps analyze data across multiple dimensions.

If you want, I can turn these into a printable quiz or add more MCQs for practice.

11) State the purpose of built-in sequence functions. (RE) 12) Define namespace and scope. (RE)
13) Differentiate between Python list and NumPy array. (RE) 14) How would you generate a
sequence of pseudorandom numbers?(RE) 15) Explain about the descriptive statistics? (UN) 16)
Justify the best method for handling missing values. (RE) 17) Short Notes: Merging of datasets?
(RE) 18) How pivot tables summarize data. (UN) 19) Assess the effectiveness of EDA methods
(EDA)? (RE) 20) What is scatter plot? (RE)

Here are concise answers based on the required taxonomy levels:

11) Purpose of built-in sequence functions (RE)


Built-in sequence functions (like len(), sum(), min(), max(), sorted()) are used to perform
common operations on sequences (lists, tuples, strings) such as counting elements, finding
extremes, sorting, and aggregating values.

12) Namespace and scope (RE)


A namespace is a container that holds names (identifiers) and their corresponding objects.
Scope defines the region of a program where a namespace is accessible (local, global, enclosing,
built-in).

13) Python list vs NumPy array (RE)


 List: Can store different data types, slower, flexible.
 NumPy array: Stores same data type, faster, supports vectorized operations, efficient for
numerical computations.

14) Generating pseudorandom numbers (RE)


Use the random module or NumPy:

 [Link]() (Python)
 [Link]() or [Link]() (NumPy)

15) Descriptive statistics (UN)


Descriptive statistics summarize and describe data features using measures like mean, median,
mode, standard deviation, variance, minimum, and maximum. They help understand data
distribution and patterns.

16) Handling missing values (RE)


Best methods include:

 Removing missing values (if small amount)


 Filling with mean/median/mode (imputation)
 Forward/backward filling
Choice depends on data size and importance of missing values.

17) Merging of datasets (RE)


Merging combines multiple datasets based on common keys or columns using operations like
inner join, outer join, left join, and right join (e.g., [Link]()).

18) Pivot tables (UN)


Pivot tables summarize data by reorganizing it, grouping values, and applying aggregate
functions (sum, mean, count) to generate insights across categories.

19) Effectiveness of EDA (RE)


EDA (Exploratory Data Analysis) is effective for:

 Understanding data structure


 Detecting patterns and trends
 Identifying outliers and anomalies
 Supporting better decision-making before modeling

20) Scatter plot (RE)


A scatter plot is a graph that displays values for two variables as points, used to identify
relationships or correlations between them.

21(a) Evaluate performance of arrays, lists, and dictionaries (EV)

Lists (Python):
 Time Complexity:
o Access: O(1)
o Insert/Delete (end): O(1), (middle): O(n)
 Space: Dynamic, can store mixed data types → less memory efficient
 Use case: General-purpose, flexible storage

NumPy Arrays:

 Time Complexity: Faster for numerical operations due to vectorization (O(n) but
optimized in C)
 Space: Memory efficient (homogeneous data)
 Use case: Scientific computing, large datasets

Dictionaries:

 Time Complexity:
o Access, Insert, Delete: O(1) (average, hash-based)
 Space: Higher memory usage due to hash table
 Use case: Fast lookup using keys

Evaluation:

 Arrays → best for performance & memory in numerical tasks


 Lists → flexible but slower
 Dictionaries → fastest for key-based retrieval

21(b) Functions improve modularity with file handling (AN)

Functions divide programs into reusable blocks, improving readability and maintenance.

Benefits:

 Code reuse
 Easier debugging
 Better organization

Example:

def read_file(filename):
with open(filename, 'r') as f:
return [Link]()

def write_file(filename, data):


with open(filename, 'w') as f:
[Link](data)
data = read_file("[Link]")
write_file("[Link]", [Link]())

Analysis:

 Each function performs a specific task


 Changes in one function don’t affect others
 Enhances modular design

22(a) Universal functions in NumPy (UN)

Universal functions (ufuncs) operate element-wise on arrays.

Features:

 Fast (implemented in C)
 Support broadcasting
 Work on entire arrays

Examples:

import numpy as np
arr = [Link]([1, 2, 3])

print([Link](arr)) # [1. , 1.41, 1.73]


print([Link](arr, 5)) # [6, 7, 8]

Explanation:

 No need for loops


 Improves performance and readability

22(b) Linear algebra functions in NumPy (EV)

Common functions:

 [Link]() → matrix multiplication


 [Link]() → inverse
 [Link]() → determinant
 [Link]() → eigenvalues

Evaluation:
 Efficient and accurate for matrix operations
 Handles large-scale problems
 Limitation: Numerical instability in some cases

Example:

import numpy as np
A = [Link]([[1,2],[3,4]])

print([Link](A))
print([Link](A))

23(a) Python app: Web API → Database (CR)

Steps:

1. Fetch data from API


2. Process JSON
3. Store in database

Example:

import requests
import sqlite3

# Fetch API data


response = [Link]("[Link]
data = [Link]()

# Store in database
conn = [Link]("[Link]")
cursor = [Link]()

[Link]("CREATE TABLE IF NOT EXISTS users(id INT, name TEXT)")

for item in data:


[Link]("INSERT INTO users VALUES (?, ?)", (item['id'],
item['name']))

[Link]()
[Link]()

Design:

 API → JSON → Database


 Scalable and reusable
23(b) Strategy for missing values, duplicates, outliers (CR)

Missing values:

 Drop if minimal
 Impute (mean/median/mode)

Duplicates:

 Use drop_duplicates()

Outliers:

 Detect using IQR or Z-score


 Remove or cap values

Strategy:

1. Identify issues
2. Apply appropriate cleaning
3. Validate results

24(a) Effectiveness of groupby (EV)

Advantages:

 Efficient aggregation
 Handles large datasets
 Simplifies analysis

Example:

[Link]('category')['sales'].sum()

Evaluation:

 Powerful for summarization


 Reduces complexity
 Limitation: Can be memory intensive

24(b) Pandas split-apply-combine workflow (CR)


Steps:

1. Split: Divide data into groups


2. Apply: Perform operations
3. Combine: Merge results

Example:

[Link]('dept')['salary'].mean()

Design Workflow:

 Load data
 Clean data
 Group data
 Apply functions
 Combine and analyze

25(a) Visualization methods: categorical vs numerical (AN)

Categorical data:

 Bar chart
 Pie chart
 Count plot

Numerical data:

 Histogram
 Line chart
 Box plot

Analysis:

 Categorical → compare groups


 Numerical → show distribution/trends
 Choosing correct chart improves interpretation

25(b) Visualization tools in Python (UN)

1. Matplotlib:
 Basic plotting

import [Link] as plt


[Link]([1,2,3])

2. Seaborn:

 Advanced statistical plots

import seaborn as sns


[Link](data)

3. Plotly:

 Interactive visualization

Explanation:

 Matplotlib → foundation
 Seaborn → better aesthetics
 Plotly → interactive dashboards

You might also like