What is the final cumulative value after applying the waterfall steps in this code?
steps = [100, -30, 20, -10] cumulative = 0 for step in steps: cumulative += step print(cumulative)
Add each step value one by one to get the final total.
The code adds 100, then subtracts 30, adds 20, and subtracts 10. The total is 80.
Given the following code to prepare data for a waterfall chart, what is the resulting DataFrame?
import pandas as pd steps = ['Start', 'Sales', 'Returns', 'Marketing', 'End'] values = [1000, 300, -50, -100, 0] cumulative = 0 cumulative_values = [] for v in values: cumulative += v cumulative_values.append(cumulative) data = pd.DataFrame({'Step': steps, 'Value': values, 'Cumulative': cumulative_values}) print(data)
Cumulative sums add each value step by step.
The cumulative column shows the running total after each step.
Which option shows the correct matplotlib code to plot a waterfall chart with positive and negative steps?
Waterfall bars start from the cumulative total so far.
Option B correctly sets the bottom parameter to the current cumulative value before adding the bar height.
What error will this code raise when preparing data for a waterfall chart?
values = [100, -20, 30] cumulative = 0 cumulative_values = [] for v in values: cumulative_values.append(cumulative + v) cumulative = v print(cumulative_values)
Check how cumulative is updated inside the loop.
The code adds v to cumulative but then resets cumulative to v, so cumulative_values are partial sums, not running totals.
You have a dataset with 5 categories and 1 total. You want to create a waterfall chart showing each category's contribution and the final total. How many bars will the chart have?
Count each category plus the total bar.
The chart shows one bar per category plus one bar for the total, so 6 bars in total.