What is the output of the following code that simulates a simple end-to-end data analysis pipeline?
import pandas as pd data = {'sales': [100, 200, 300, 400], 'cost': [50, 80, 120, 150]} df = pd.DataFrame(data) df['profit'] = df['sales'] - df['cost'] total_profit = df['profit'].sum() print(total_profit)
Calculate profit for each row, then add all profits.
The profit column is sales minus cost: [50, 120, 180, 250]. Summing these gives 600.
Given the DataFrame below, what is the output after filtering rows where 'age' > 30 and calculating the mean of 'income'?
import pandas as pd data = {'name': ['Anna', 'Bob', 'Cara', 'Dan'], 'age': [25, 35, 45, 28], 'income': [50000, 60000, 70000, 55000]} df = pd.DataFrame(data) filtered = df[df['age'] > 30] mean_income = filtered['income'].mean() print(mean_income)
Only include rows with age above 30, then average their income.
Rows with age > 30 are Bob (60000) and Cara (70000). Their average is (60000 + 70000) / 2 = 65000.
Which plot best shows the trend of monthly sales over time from the DataFrame below?
import pandas as pd import matplotlib.pyplot as plt data = {'month': ['Jan', 'Feb', 'Mar', 'Apr'], 'sales': [200, 220, 250, 270]} df = pd.DataFrame(data) plt.plot(df['month'], df['sales']) plt.title('Monthly Sales Trend') plt.xlabel('Month') plt.ylabel('Sales') plt.show()
Look for a plot that connects points to show change over time.
A line plot connects points in order, showing the upward trend in sales from January to April.
What error does the following code raise when trying to remove rows with missing values?
import pandas as pd data = {'A': [1, 2, None], 'B': [4, None, 6]} df = pd.DataFrame(data) df_clean = df.dropna(inplace=True) print(df_clean)
Check what dropna returns when inplace=True is used.
dropna with inplace=True modifies df in place and returns None. So df_clean is None and printing it shows None.
You have sales data with missing values and outliers. Which approach best represents an end-to-end analysis to prepare data for reliable insights?
Think about the logical order of preparing data before analysis and visualization.
End-to-end analysis means cleaning data first (missing values, outliers), then analyzing and visualizing to get reliable insights.