POC Data Management & Integration 2 — Questions and Answers
Question 1: Which pandas method is used to merge two DataFrames on a common column, similar to a SQL JOIN?
- concat()
- merge() (Correct answer)
- join()
- append()
Correct answer: merge()
pd.merge() combines DataFrames based on one or more shared key columns, mirroring SQL JOIN behavior.
Question 2: When reading a CSV file with pandas, which parameter specifies a custom delimiter instead of a comma?
- delimiter
- sep (Correct answer)
- split
- divider
Correct answer: sep
The 'sep' parameter in pd.read_csv() defines the character used to separate fields in the file.
Question 3: Which Python library provides the 'connect()' function used to establish a connection to a SQLite database?
- pymysql
- psycopg2
- sqlite3 (Correct answer)
- sqlalchemy
Correct answer: sqlite3
The built-in sqlite3 module's connect() function creates or opens a SQLite database file.
Question 4: What does the pandas 'fillna()' method do?
- Removes rows with NaN values
- Replaces NaN values with a specified value (Correct answer)
- Counts NaN values per column
- Fills a new column with zeros
Correct answer: Replaces NaN values with a specified value
fillna() replaces missing (NaN) values in a DataFrame or Series with a given scalar, dict, or method.
Question 5: In Python's sqlite3 module, what object is used to execute SQL statements?
- Connection
- Cursor (Correct answer)
- Session
- Query
Correct answer: Cursor
A Cursor object obtained via connection.cursor() is used to execute SQL commands and fetch results.
Question 6: Which pandas method converts a DataFrame column containing string dates into datetime objects?
- df['col'].astype('datetime')
- pd.to_datetime(df['col']) (Correct answer)
- df['col'].to_date()
- df['col'].parse_date()
Correct answer: pd.to_datetime(df['col'])
pd.to_datetime() parses string or numeric representations of dates into pandas Timestamp objects.
Question 7: What is the purpose of the 'chunksize' parameter in pd.read_csv()?
- Sets the maximum file size to read
- Returns an iterator that reads the file in chunks of rows (Correct answer)
- Limits the number of columns parsed
- Defines compression block size
Correct answer: Returns an iterator that reads the file in chunks of rows
chunksize causes read_csv() to return a TextFileReader iterator, yielding DataFrames of the specified row count for memory-efficient processing.
Which pandas method is used to merge two DataFrames on a common column, similar to a SQL JOIN?