Given a DataFrame with columns having spaces and uppercase letters, what will be the column names after applying the standardization code?
import pandas as pd df = pd.DataFrame(columns=['First Name', 'Last Name', 'Age']) df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_') print(list(df.columns))
Think about what each string method does: strip(), lower(), and replace().
The code removes spaces around column names, converts all letters to lowercase, and replaces spaces with underscores. So 'First Name' becomes 'first_name'.
After standardizing column names, you want to keep only columns that start with 'user_'. How many columns remain?
import pandas as pd df = pd.DataFrame(columns=['User ID', 'User Name', 'Age', 'user_email']) df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_') filtered_cols = [col for col in df.columns if col.startswith('user_')] print(len(filtered_cols))
Check which columns start exactly with 'user_' after standardization.
After standardization, columns are ['user_id', 'user_name', 'age', 'user_email']. 'user_id', 'user_name', and 'user_email' start with 'user_'. So 3 columns match.
Identify the error raised by this code snippet:
import pandas as pd df = pd.DataFrame(columns=['Name', 'Age']) df.columns = df.columns.str.lower().replace(' ', '_')
Remember that str.lower() returns an Index object with string methods available, but replace is a string method, not an Index method.
The replace method is called on the Index object, which does not have it. The correct way is to use str.replace() to apply replace on each string in the Index.
Choose the code snippet that correctly standardizes DataFrame columns by making them lowercase and replacing spaces with underscores.
Check which methods are available on the Index object and how to chain them.
Only str.lower() and str.replace() are valid methods on the Index's string accessor. The correct chain is df.columns.str.lower().str.replace(' ', '_').
Choose the best reason why standardizing column names is a crucial step in data science workflows.
Think about how consistent naming helps when writing code and sharing data.
Standardizing column names avoids bugs caused by inconsistent naming, improves readability, and helps when combining datasets from different sources.