




































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





































































Question 1 Which built-in Python collection provides O(1) average-time complexity for membership tests? A) list B) dict C) set D) tuple Answer: C Explanation: A set is implemented as a hash table, giving constant-time average lookup, whereas lists and tuples require O(n) scans and dicts test keys, not arbitrary values. Question 2 In a Python try-except-finally block, which clause is guaranteed to run even if the except block re-raises an exception? A) try B) except C) finally D) else Answer: C Explanation: The finally clause always executes after the try block completes, regardless of whether an exception was handled or re-raised. Question 3 What does the following list comprehension produce? [[i*j for j in range(3)] for i in range(2)] A) [[0,0,0],[0,0,0]] B) [[0,1,2],[0,1,2]] C) [[0,0,0],[1,2,3]] D) [[0,0,0],[0,1,2]] Answer: D Explanation: For i=0 the inner loop yields 0*0,0*1,0*2 → [0,0,0]; for i=1 it yields 1*0,1*1,1*2 → [0,1,2]. Question 4 Which command creates an isolated Python environment in the current directory named env? A) python -m venv env
B) pip install env C) conda create -n env D) virtualenv env Answer: A Explanation: python -m venv env uses the standard library venv module to generate a directory env containing a self-contained interpreter and site-packages. Question 5 In pytest, which fixture scope runs only once per test session? A) function B) class C) module D) session Answer: D Explanation: The session scope creates the fixture a single time for the entire pytest run, whereas function, class, and module are more granular. Question 6 Which of the following statements about Python’s lambda functions is FALSE? A) They can contain multiple expressions separated by commas. B) They are anonymous functions. C) They can be used as arguments to map. D) They return the value of the single expression they contain. Answer: A Explanation: A lambda can only contain a single expression; it cannot hold multiple statements or expressions separated by commas. Question 7 When using pip freeze > requirements.txt, what information is stored in the file? A) Only package names. B) Package names with exact version pins. C) The output of pip list. D) The virtual environment’s path.
Question 11 In Pandas, which method efficiently fills missing numeric values with the median of the column? A) df.fillna(df.mean()) B) df.fillna(df.median()) C) df.replace(np.nan, df.median()) D) df.interpolate() Answer: B Explanation: df.fillna(df.median()) computes the median per column and replaces NaNs with those values; it is vectorized and avoids explicit loops. Question 12 What does the Pandas pivot_table function primarily enable? A) Reshaping data from long to wide format using aggregation. B) Merging two DataFrames on a key column. C) Sorting rows by multiple columns. D) Converting a DataFrame to a NumPy array. Answer: A Explanation: pivot_table aggregates data while reshaping it, allowing you to specify index, columns, values, and an aggregation function, thus turning long data into a wide matrix. Question 13 Which Pandas operation is lazy and does not compute results until a subsequent action is called? A) df.apply() B) df.groupby() C) df.eval() D) None; Pandas is eager. Answer: D Explanation: Pandas evaluates operations eagerly; there is no built-in lazy execution model like Spark’s. Question 14 In a Pandas DataFrame, what does df.loc['2021-01-01':'2021- 01-31'] accomplish? A) Select rows by integer position.
B) Slice rows based on the index label range (inclusive). C) Filter columns named '2021-01-01' to '2021-01-31'. D) Raise a KeyError if the index is not sorted. Answer: B Explanation: .loc performs label-based slicing; when the index is a datetime index, the range includes both endpoints. Question 15 Which NumPy function creates an uninitialized array of shape (3,4) with dtype float64? A) np.zeros((3,4), dtype=float) B) np.empty((3,4), dtype=np.float64) C) np.arange(12).reshape(3,4) D) np.full((3,4), np.nan) Answer: B Explanation: np.empty allocates memory without initializing entries, returning an array of the specified shape and dtype. Question 16 When broadcasting a 1-D NumPy array of shape (3,) against a 2 - D array of shape (5,3), what is the result shape? A) (5,3) B) (3,5) C) (5,1,3) D) Broadcast error. Answer: A Explanation: The 1-D array aligns with the last dimension of the 2-D array; NumPy broadcasts it across the first dimension, yielding shape (5,3). Question 17 Which NumPy function should be used to compute the dot product of two 2-D arrays A (shape 2×3) and B (shape 3×4)? A) np.multiply(A, B) B) np.dot(A, B) C) np.cross(A, B) D) np.inner(A, B)
Question 21 Which of the following Spark DataFrame operations is lazy? A) df.show() B) df.collect() C) df.filter(col("age") > 30) D) df.write.parquet("s3://bucket") Answer: C Explanation: Transformations like filter build a logical plan but do not trigger execution. Actions such as show, collect, or write cause the plan to be evaluated. Question 22 How can you register a Python function as a Spark UDF that returns an integer? A) spark.udf.register("my_udf", my_func, IntegerType()) B) spark.sql.registerUDF(my_func, "int") C) df.withColumn("col", my_func(col("col")) ) D) spark.createUDF(my_func, "int") Answer: A Explanation: spark.udf.register takes the name, the Python callable, and the return DataType (e.g., IntegerType). This makes the function usable in SQL expressions. Question 23 In Snowpark for Python, which method creates a DataFrame from a local Pandas DataFrame? A) session.create_dataframe(pandas_df) B) session.read.pandas(pandas_df) C) session.from_pandas(pandas_df) D) session.upload(pandas_df) Answer: A Explanation: session.create_dataframe can accept a Pandas DataFrame and convert it into a Snowpark DataFrame that can be processed inside Snowflake. Question 24 Which Snowpark function allows you to write a DataFrame to a Snowflake stage in Parquet format?
A) df.write.parquet("@my_stage") B) df.save_as_table("my_table") C) df.to_parquet("@my_stage") D) df.write.mode("overwrite").save("@my_stage") Answer: A Explanation: Snowpark mirrors the Spark API; write.parquet writes the DataFrame to the specified stage path using Parquet. Question 25 When reading a CSV file with Pandas, which parameter automatically infers and parses dates in columns named date? A) parse_dates=True B) infer_datetime_format=True C) parse_dates=["date"] D) date_parser="date" Answer: C Explanation: parse_dates accepts a list of column names to treat as dates; Pandas then attempts to parse those columns into datetime64[ns]. Question 26 Which of the following Python libraries is best suited for handling Avro schema evolution? A) fastavro B) csv C) openpyxl D) xmltodict Answer: A Explanation: fastavro provides fast reading/writing of Avro files and includes utilities for handling schema evolution (reader and writer schemas). Question 27 In the context of cloud storage, which compression codec is natively supported by AWS S3 when using the boto3 upload_fileobj method? A) LZMA B) Snappy C) GZIP
Explanation: GET is the safe, idempotent method for retrieving resources; it should not modify server state. Question 31 In the requests library, how can you set a timeout of 10 seconds for a request? A) requests.get(url, timeout=10) B) requests.get(url, time=10) C) requests.get(url, delay=10) D) requests.get(url, limit=10) Answer: A Explanation: The timeout parameter specifies the maximum number of seconds to wait for a response before raising a Timeout exception. Question 32 Which Google Cloud SDK class is used to interact with Cloud Storage buckets in Python? A) google.cloud.storage.Client B) google.cloud.storage.Bucket C) google.cloud.storage.Object D) google.cloud.storage.Storage Answer: A Explanation: google.cloud.storage.Client is the entry point; from it you obtain Bucket objects and perform operations like upload/download. Question 33 When compressing JSON data for storage, which combination yields the best size reduction without losing readability on decompression? A) JSON → GZIP B) JSON → BZIP2 → Base C) JSON → ZIP → AES encryption D) JSON → LZMA → Hex encoding Answer: A Explanation: GZIP provides strong compression for text data like JSON and is widely supported; the other options add unnecessary steps or overhead.
Question 34 In a batch ETL pipeline, which Python scheduling library would you use for a simple daily run without a full orchestrator? A) schedule B) croniter C) airflow D) prefect Answer: A Explanation: The schedule library offers a lightweight API for defining periodic jobs (e.g., every().day.at("02:00")). croniter parses cron expressions but does not schedule jobs. Question 35 Which of the following statements about Structured Streaming in PySpark is TRUE? A) It processes data only when a foreachBatch action is called. B) It requires you to define a static schema before reading. C) It cannot write to Parquet files. D) It automatically caches all incoming data in memory. Answer: B Explanation: Structured Streaming needs a known schema at read time (e.g., when reading JSON). The other statements are false. Question 36 In Apache Airflow, which argument of a PythonOperator determines the callable that will be executed? A) task_id B) python_callable C) op_args D) dag Answer: B Explanation: python_callable receives the reference to the Python function that the operator should run. Question 37 What is the purpose of the default_args dictionary when defining an Airflow DAG? A) To store global variables for the DAG.
Explanation: Integration tests verify that the pipeline works with external services (e.g., databases) in a staging environment, providing a safety net before production rollout. Question 41 Which Python logging level captures the most detailed information? A) INFO B) WARNING C) DEBUG D) CRITICAL Answer: C Explanation: DEBUG is lower than INFO and records fine-grained diagnostic output, useful for troubleshooting. Question 42 Which CloudWatch metric would you monitor to detect a Spark executor that is running out of memory? A) CPUUtilization B) MemoryUtilization (custom) C) NetworkIn D) DiskReadOps Answer: B Explanation: Spark does not emit a native MemoryUtilization metric, but you can publish a custom CloudWatch metric from your Spark driver/executor that tracks JVM heap usage; this is the most direct indicator of OOM risk. Question 43 In Python, which library provides a convenient wrapper for interacting with AWS Secrets Manager? A) boto3 B) awscli C) botocore D) aws-sdk Answer: A Explanation: boto3 is the official AWS SDK for Python and includes a client('secretsmanager') interface to retrieve secrets securely.
Question 44 Which function from the cryptography library creates a symmetric key for AES-256 encryption? A) Fernet.generate_key() B) os.urandom(32) C) AES.generate_key(256) D) hashlib.sha256() Answer: B Explanation: AES-256 requires a 32-byte (256-bit) key; os.urandom(32) returns cryptographically strong random bytes suitable for use as the key. Fernet uses its own format and size. Question 45 In Great Expectations, what does the expect_column_values_to_be_unique expectation validate? A) That the column contains no nulls. B) That each value in the column appears only once. C) That the column data type matches the expectation. D) That the column values are within a specified range. Answer: B Explanation: This expectation ensures the column has unique values, useful for primary key validation. Question 46 Which IAM policy element specifies the actions that are allowed or denied? A) Resource B) Effect C) Action D) Condition Answer: C Explanation: The Action field lists API calls (e.g., s3:GetObject) that the policy statement governs. Question 47 When using Python’s multiprocessing.Pool.map, what happens if one of the worker processes raises an exception? A) The exception is silently ignored.
C) df.write.mode("overwrite") D) df.persist() Answer: B Explanation: coalesce reduces the number of partitions without a full shuffle, allowing you to control the number of output files; repartition(1) would create a single large file but may cause a shuffle and performance bottleneck. Question 51 Which Python construct is most appropriate for reading a large CSV file line-by-line without loading the entire file into memory? A) pandas.read_csv() B) csv.reader(open(file)) inside a for loop C) np.loadtxt() D) json.load() Answer: B Explanation: The csv module reads iteratively, yielding each row; this approach streams data and avoids full memory consumption. Question 52 In Pandas, which method returns a new DataFrame containing only rows where column status equals 'active'? A) df.filter(df.status == 'active') B) df.where(df.status == 'active') C) df.loc[df['status'] == 'active'] D) df.select(df.status == 'active') Answer: C Explanation: .loc with a boolean mask selects rows meeting the condition, returning a new DataFrame. Question 53 Which of the following Spark SQL functions can be used to remove duplicate rows based on all columns? A) distinct() B) dropDuplicates() C) unique() D) Both A and B Answer: D
Explanation: Both distinct() and dropDuplicates() achieve the same result; distinct() is a SQL-style operation, while dropDuplicates() is a DataFrame method. Question 54 In PySpark, what does the broadcast() function do? A) Sends a DataFrame to all executors for a join, reducing shuffle. B) Replicates a column across all rows. C) Converts a DataFrame to a Pandas DataFrame. D) Persists a DataFrame in memory only. Answer: A Explanation: broadcast(df) marks a small DataFrame to be cached on each executor, enabling a broadcast join that avoids shuffling the larger table. Question 55 Which Snowpark method converts a Snowpark DataFrame to a Pandas DataFrame? A) to_pandas() B) collect().to_pandas() C) to_pandas() is not supported; you must use to_pandas() after session.sql D) df.to_pandas() Answer: D Explanation: Snowpark provides a to_pandas() method that pulls the result set into a local Pandas DataFrame. Question 56 When using the boto3 S3 client’s upload_fileobj method, which parameter controls multipart upload threshold? A) Config with multipart_threshold B) ChunkSize C) MaxConcurrency D) TransferConfig with multipart_threshold Answer: D Explanation: TransferConfig allows you to set multipart_threshold; the client uses it to decide when to split the upload into parts.
C) cryptography.hazmat.primitives.kdf.pbkdf2.PBKDF2HMAC D) cryptography.hazmat.primitives.ciphers.Cipher Answer: A Explanation: The RSA module’s generate_private_key creates a private key; the public key can be derived from it. Question 61 In Great Expectations, what is the purpose of a suite? A) To group expectations together for a dataset. B) To define a data source connection. C) To schedule automated validation runs. D) To store raw data snapshots. Answer: A Explanation: An Expectation Suite is a collection of expectations that can be applied to a batch of data for validation. Question 62 Which SQL clause does Great Expectations use internally when validating a expect_table_row_count_to_be_between expectation? A) SELECT COUNT(*) FROM B) SELECT * FROM LIMIT C) SELECT MIN(row_id) FROM D) SELECT SUM(1) FROM Answer: A Explanation: Row-count validation simply executes a COUNT(*) aggregation to compare against the defined bounds. Question 63 In a multi-tenant data lake, which AWS service can be used to enforce fine-grained column-level access control via Python SDK? A) AWS Lake Formation B) Amazon Athena C) Amazon Redshift D) AWS Glue Data Catalog Answer: A
Explanation: Lake Formation provides column-level permissions and can be managed programmatically through its API. Question 64 Which Spark configuration controls the amount of memory reserved for broadcast variables? A) spark.sql.autoBroadcastJoinThreshold B) spark.broadcast.blockSize C) spark.memory.fraction D) spark.broadcast.compress Answer: B Explanation: spark.broadcast.blockSize sets the size of each block of a broadcast variable; larger blocks reduce overhead but increase memory per executor. Question 65 In Python’s concurrent.futures.ThreadPoolExecutor, which method submits a callable for asynchronous execution? A) run() B) execute() C) submit() D) dispatch() Answer: C Explanation: submit(fn, *args, **kwargs) schedules the function and returns a Future object. Question 66 Which of the following is a recommended way to avoid “driver OOM” when collecting a Spark DataFrame to the driver? A) Use df.collect() directly. B) Increase spark.driver.memory indefinitely. C) Write the DataFrame to external storage (e.g., S3) instead of collecting. D) Convert the DataFrame to Pandas before writing. Answer: C Explanation: Pulling large datasets to the driver can exceed memory; persisting to external storage keeps data distributed and avoids driver memory pressure.