What will be the output of this code snippet that uses pandas built-in plotting on a DataFrame with missing values?
import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({ 'A': [1, 2, None, 4], 'B': [4, None, 6, 8] }) df.plot() plt.close() # Prevent plot display in test environment print(df.plot().lines[0].get_xydata())
Think about how pandas handles None values in plotting.
Pandas plots the data points including NaN (converted from None) as gaps. The line for column 'A' includes a NaN at index 2, so the plot data includes that point with nan y-value.
Given this DataFrame, how many lines will pandas plot by default?
import pandas as pd df = pd.DataFrame({ 'X': [1, 2, 3], 'Y': [4, 5, 6], 'Z': [7, 8, 9] }) plot_obj = df.plot() num_lines = len(plot_obj.lines) print(num_lines)
Each column in the DataFrame is plotted as a separate line by default.
By default, pandas plots each column as a separate line. Since there are 3 columns, 3 lines are plotted.
Which option best describes why pandas built-in plotting is useful for quick data insights?
Think about the main advantage of built-in plotting for beginners and quick checks.
Pandas built-in plotting is designed for quick, simple visualizations directly from data, helping users see trends and patterns fast without complex setup.
What error will this code produce when run?
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3]}) df.plot(kind='scatter', x='A', y='B')
Check if the DataFrame has the columns used for x and y.
The DataFrame does not have a column named 'B', so trying to plot y='B' raises a KeyError.
Which reason best explains why pandas built-in plotting is preferred during exploratory data analysis (EDA)?
Consider how pandas plotting works with DataFrames and Series.
Pandas plotting works directly on pandas objects, so you don't need to convert data before plotting, which speeds up EDA.