AAmit’s LibraryLEARN · PRACTISE · REFLECT

BCA

Python data laboratory

Study map: Original subject-specific business–computing teaching chapter

A data lab turns raw records into an answer to a defined question. Begin with provenance: where the file came from, what each row means, when it was produced and which population it describes. The workshop uses a small synthetic order file designed to reveal errors. It is not a sample from an actual retailer and cannot establish market demand, customer behaviour or profitability.

Foundation: treat a dataset as evidence with boundaries

A data lab turns raw records into an answer to a defined question. Begin with provenance: where the file came from, what each row means, when it was produced and which population it describes. The workshop uses a small synthetic order file designed to reveal errors. It is not a sample from an actual retailer and cannot establish market demand, customer behaviour or profitability.

A CSV stores fields as text separated according to a file format. Parsing the file is different from understanding it. A quantity field may contain invalid text; an identifier may be blank; a repeated row may represent an accidental export. Keep the original input available and produce a separate classification rather than editing away inconvenient records before explaining them.

Write the reporting question first: what is the total accepted order-line value under the stated contract? This wording identifies the measure, inclusion rule and boundary. It does not ask for total cash or profit. A small clear question is a better starting point than building a dashboard whose users disagree about the meaning of every number.

For the Python exercise, open a CSV file with newline="" and a declared encoding. The default csv.reader returns strings; numeric conversion must follow the field contract. Quoting modes can change conversion behaviour, so record the chosen dialect and options. A quoted field may contain a newline: reader.line_num counts source lines, not parsed records. Assign a separate input-record number for reconciliation.

Further reading: Python csv reference: parsing, conversion and record boundaries

Undergraduate: classify, reconcile and report

The exercise classifies each input as accepted, replayed, conflicting or rejected. Accepted means it satisfies the contract and introduces a new identifier. Replayed means an existing identifier repeats equivalent content. Conflicting means the identifier repeats with different content. Rejected means the row cannot satisfy a required rule. These categories make uncertainty and correction work visible.

Reconcile both counts and money. The input count must equal the sum of classification counts. Accepted quantities and values must agree between the Python calculation and SQL report. An order that is replayed does not add value a second time. A conflicting row is retained as an exception, not selected simply because it appears last.

Use explicitly labelled output. Show accepted value in paise and convert to rupees for presentation. Keep the conversion separate from the calculation. Include rejection reasons and the scope of the fixture. A polished chart without an inclusion definition can mislead more effectively than a plain table with honest boundaries.

A count reconciliation is meaningful only after the file has been read successfully and each input record has exactly one outcome. A missing file or an unhandled failure must not be reported as a successful empty batch. Handle expected conversion errors narrowly; let unexpected failures remain visible. Preserve any partial-run status separately from completed totals. For a hand check, three accepted records, one replay and one conflict give five input records and zero rejections; without quantities and prices, these counts do not determine money.

Further reading: Python tutorial: handling expected and unexpected exceptions

Postgraduate: connect analysis to decisions and feedback

Apply a question–provenance–validation–analysis–decision framework. Define the business question, inspect evidence origin, apply justified rules, calculate and interpret, then specify a decision and review. A reporting pipeline should not automatically approve the commercial action merely because it produced a number. A manager must consider capacity, customer commitments and uncertainty outside the file.

Data exclusion requires care. If invalid rows are more common for one department, a report may systematically underrepresent its work. Investigate the reason before interpreting lower accepted value as poorer performance. Staff may lack the correct form, or identifiers may be generated inconsistently. Consultation can improve the source process while preserving accountability for data quality.

Establish a feedback loop. Send useful exception information to the responsible owner, allow correction with traceability, and measure whether recurring causes decrease. Protect employee wellbeing by avoiding blame based on unexplained rejection counts. The computer can consistently apply a rule; the organisation must decide whether the rule remains appropriate and whether workers have the support to satisfy it.

Research: distinguish a teaching fixture from general evidence

A research question could examine whether transparent exception categories improve reconciliation accuracy and correction time. Define accuracy independently, specify the participant task and compare equivalent datasets. The synthetic fixture is useful for controlled testing, but its small size and designed errors do not represent the distribution of real work.

Keep analytical and predictive claims separate. Descriptive totals explain the accepted fixture; they do not forecast demand. A future predictive study needs a target, time-aware validation and attention to leakage. A field produced after approval cannot legitimately predict a decision that must be made before approval. Building a complex model does not repair an undefined business question.

Submit a data dictionary, category table, reconciliation, exception-owner map and decision memo. Explain which findings are guaranteed by the chosen contract and which require empirical investigation. Ask who can correct a conflict, whom a missing record affects, where evidence is stored and when the report becomes too old for the intended decision. Learning ends with an accountable interpretation, not only successful code execution.

Study questions and answers

Why preserve rejected records with reasons?

Keep the source row or its traceable reference and the reason it failed the declared rule. A blank quantity and an observed zero communicate different evidence; silently replacing a blank with zero hides the omission. A correction should record the revised value and its reason without silently rewriting the input. An unreadable source file is a failed run, not a batch of rejected rows; report that failure separately. The example uses synthetic data, and operational retention must follow the applicable data-handling policy. Indicative marking: Explain omission and correction traceability (3); distinguish a blank from an observed zero with an example (3); preserve the source and correction reason (2); distinguish row rejection from a failed run or state a justified retention boundary (2).

Five inputs yield three accepted, one replay and one conflict. What is the count reconciliation?

Three accepted + one replay + one conflict + zero rejected = five classified input rows. Each row receives one category under the stated contract. Only the three accepted rows contribute to accepted order-line value; the replay adds no second value and the conflicting row remains an exception. The accepted quantities and unit prices are not supplied, so no monetary total can be calculated. This count reconciliation checks completeness of classification, not whether the classification rules are correct or whether payment was received. Indicative marking: Give 3 + 1 + 1 + 0 = 5 with category labels (3); explain one category per input row (2); exclude replay and conflict from additional accepted value (3); state that prices/quantities are missing and counts do not prove payment or rule correctness (2).

Why can departmental comparisons be biased by validation?

Different rejection rates may reflect source tools or missing fields rather than performance. Investigate exclusions and their causes before judging departments. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Can this fixture support demand prediction?

No. It is designed synthetic data, not representative demand evidence. Prediction needs an explicit target, suitable sampling and time-aware validation without future information leakage. Indicative marking: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Extended practice questions

Why preserve rejected records with reasons?

They explain omissions, enable correction and reveal source-process problems. Replacing them silently with zero destroys the distinction between absent evidence and valid zero values.

Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Marks: 10

Five inputs yield three accepted, one replay and one conflict. What is the count reconciliation?

3 + 1 + 1 + 0 rejected = 5 input rows. Monetary totals use the three accepted records only; counts alone do not establish their value.

Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Marks: 10

Why can departmental comparisons be biased by validation?

Different rejection rates may reflect source tools or missing fields rather than performance. Investigate exclusions and their causes before judging departments.

Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Marks: 10

Can this fixture support demand prediction?

No. It is designed synthetic data, not representative demand evidence. Prediction needs an explicit target, suitable sampling and time-aware validation without future information leakage.

Marking guide: Correct concept or result 3; explanation 3; relevant case application 2; boundary or limitation 2.

Marks: 10

A CSV column looks numeric but contains blank strings and a value with an unexpected currency symbol. What should the parsing exercise do?

Inspect the file schema, units and source conventions before conversion. Define how blanks, malformed values and permitted symbols are handled, keeping rejected rows and reasons visible. Avoid converting every failure to zero, which would silently change the measure. Use explicit parsing rules and test synthetic examples. The CSV reader supplies fields; it does not decide their business meaning or guarantee numeric validity. Finance or the relevant data owner confirms units and missing-value policy, while the learner implements and checks the transformation. Retain original values so an unexpected result can be investigated.

Marking guide: Schema/units; explicit missing/malformed rules; no zero substitution; owner; preserved raw values. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

Compare a missing value with a genuine numeric zero in business data.

A genuine zero states that the measured quantity is zero under the defined observation. A missing value states that the quantity is not supplied or known in the record. Treating both as zero changes totals, averages and interpretation. Investigate whether missingness relates to collection failures or a particular group before deciding a handling rule. Document the denominator used in summaries. A script can implement a selected rule consistently, but the data owner must justify it. Do not infer that a missing sale means no sale occurred or that a blank cost means the item was free.

Marking guide: Observed zero versus absent information; summaries/denominators; missingness; justified rule. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

The synthetic amount field contains 10, 20, a blank, 30 and 40. Calculate the mean over observed values and the mean if the blank is incorrectly replaced by zero.

Observed values sum to 100 across four records, so their mean is 100/4 = 25. Replacing the blank with zero yields 100/5 = 20. The difference is five units, but neither calculation reveals what the missing value truly was. Report the observed-value denominator and the missing count. If missingness is systematic, the observed mean may also be unrepresentative. The example demonstrates why a convenient parsing default can alter a business result. Keep the original field and a documented handling rule rather than silently filling it for an apparently complete dashboard.

Marking guide: Observed 25; zero-filled 20; denominators; unknown value and missingness; preserved rule. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

Design a reproducible Python data-summary exercise.

Provide a synthetic CSV, its column meanings and units, and the expected record population. Define parsing, missing-value and duplicate rules before producing the summary. Include a malformed amount, a blank and a repeated identity, then reconcile accepted and rejected counts. Compare a small output with a hand calculation and keep the source file unchanged. State the Python dependencies and execution instructions. A reproducible script supports review, but an error-free run does not prove that the data are representative or that the selected summary answers the business question. Keep those interpretation questions explicit.

Marking guide: Input/schema/units; explicit rules; difficult records/counts; hand check; reproducibility versus validity. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

Revision cards

Why specify data types when importing a business dataset?

Types influence comparison, arithmetic and missing-value treatment. An identifier with leading zeros should often remain text. Automatic inference can silently alter meaning, so inspect the schema and validate representative values before relying on downstream calculations.

A CSV column looks numeric but contains blank strings and a value with an unexpected currency symbol. What should the parsing exercise do?

Define parsing and missing-value rules, preserve raw values and log rejected rows. A CSV reader does not establish numeric validity or business meaning.

Compare a missing value with a genuine numeric zero in business data.

Zero is a measured quantity; missing means absent information. Substituting zero can distort summaries and should not be an automatic parsing rule.

The synthetic amount field contains 10, 20, a blank, 30 and 40. Calculate the mean over observed values and the mean if the blank is incorrectly replaced by zero.

Observed mean 25 over four values; zero-filled mean 20 over five. The blank is still unknown, and the observed mean may be unrepresentative.

Design a reproducible Python data-summary exercise.

Provide schema and synthetic exceptions, reconcile counts and compare a hand calculation. An error-free script is not proof of representative data or a suitable measure.

What should a data-cleaning notebook preserve?

Keep the original input, declared rules, transformation steps and evidence of changes. Cleaning should be reproducible and accountable. Replacing suspicious values by intuition can erase the distinction between an observed fact, a correction and an unresolved exception.

Why check notebook execution order?

Interactive notebooks retain state, so later output may depend on cells executed outside their displayed order. Restart and run the intended sequence. A successful cell alone does not show that another learner can reproduce the result from a clean session.

How should a script handle an invalid input row?

Apply a documented policy: reject, quarantine or transform with appropriate evidence, and report the affected scope. Avoid silent loss or unsupported imputation. The right treatment depends on the decision and whether the row can be corrected reliably.

What makes a plotted business comparison reproducible?

Record the input version, filtering, transformations, aggregation, units and plotting code. Explain what was excluded. A saved image presents the result but cannot by itself establish which records and choices generated the apparent difference.

Practice task

Complete computing-workshop.html: predict category counts and totals, run the script and tests, then submit the six portfolio deliverables.

Sources and further reading

Open interactive reading and progress tools