single
Challenge: Extract and Report Key Insights
Veeg om het menu te tonen
Veeg om te beginnen met coderen
Create a function extract_significant_changes(df, threshold) that accepts a DataFrame with a value column and a numeric threshold, identifies all points where the value changed significantly compared to the previous row, prints a summary report, and returns the list of changes.
Loop through the value column using .items() to access both the index and value. For each row after the first, compare it to the previous value — if the absolute difference is greater than threshold, record the change.
For each significant change, store:
index— the current row's indexprev_index— the previous row's indexprev_value— the previous valuecurrent_value— the current valuechange— the difference (current minus previous, can be negative)
Print a summary report in this exact format:
Significant changes (threshold: {threshold}):
At {index}, value changed from {prev_value} to {current_value} (change: {change})
At {index}, value changed from {prev_value} to {current_value} (change: {change})
...
For example, given values [100, 110, 90, 92, 130] with threshold=15, the output should be:
Significant changes (threshold: 15):
At 2, value changed from 110 to 90 (change: -20)
At 4, value changed from 92 to 130 (change: 38)
Return the list of recorded change dictionaries at the end of the function.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.