Python and R Programming
Pandas DataFrames, Wrangling, Cleaning and Aggregation
PGCP-BDA
Series and DataFrame
A Series is a labeled one-dimensional array; a DataFrame is a labeled two-dimensional table whose columns can have different dtypes.
A Series is a labeled one-dimensional array; a DataFrame is a labeled two-dimensional table whose columns can have different dtypes. Python’s runtime model matters: names refer to objects, operations are dispatched by type and mutability determines whether an operation changes an object or creates another one. Clear code preserves object boundaries, validates external input and uses exceptions to report conditions a caller can handle. A small example of Series and DataFrame should be traced from object or input creation through every relevant operation and return value. Include an empty or null-like case and one invalid case so the exception or boundary behavior is visible. Production use should keep external input validation, business logic, storage and presentation in separate functions or classes.
index and columns
Pandas indexes label rows and columns and drive alignment, selection, joins and duplicate-label behavior.
Pandas indexes label rows and columns and drive alignment, selection, joins and duplicate-label behavior. A concise Python expression is useful only when its data flow remains readable. Choose the built-in type or library abstraction that matches ordering, uniqueness, lookup, numerical or tabular requirements. Observe return values and side effects and keep transformation code separate from input, storage and presentation. When using index and columns, document which object owns mutable state, which caller releases resources and which failures can propagate. Names and types should express the contract without forcing a reader to inspect every implementation detail. Automated tests should verify the public behavior and avoid depending on incidental internal ordering unless that ordering is part of the contract.
data loading
Data loading parses an external representation under explicit delimiter, encoding, schema, missing-value, date and error policies.
Data loading parses an external representation under explicit delimiter, encoding, schema, missing-value, date and error policies. The mechanism should be demonstrated with a small valid case, a boundary case and an invalid case. This reveals type conversions, empty inputs, missing values and exception behavior before the same code is placed in an AI data pipeline or web service. The practical value of data loading appears when the program changes. A sound design permits one behavior to be replaced or extended without duplicating validation and cleanup code. Logging should identify the operation and outcome without exposing credentials or personal data and concurrent use must be supported explicitly rather than assumed from a successful single-threaded example.
selection and filtering
loc selects by labels, iloc by positions and Boolean masks retain rows satisfying aligned conditions.
loc selects by labels, iloc by positions and Boolean masks retain rows satisfying aligned conditions. Python’s runtime model matters: names refer to objects, operations are dispatched by type and mutability determines whether an operation changes an object or creates another one. Clear code preserves object boundaries, validates external input and uses exceptions to report conditions a caller can handle. A small example of selection and filtering should be traced from object or input creation through every relevant operation and return value. Include an empty or null-like case and one invalid case so the exception or boundary behavior is visible. Production use should keep external input validation, business logic, storage and presentation in separate functions or classes.
missing values
Missing-value handling distinguishes absent observations from valid zeros or empty text and uses detection, imputation.
Missing-value handling distinguishes absent observations from valid zeros or empty text and uses detection, imputation, exclusion or missingness indicators with justification. A concise Python expression is useful only when its data flow remains readable. Choose the built-in type or library abstraction that matches ordering, uniqueness, lookup, numerical or tabular requirements. Observe return values and side effects and keep transformation code separate from input, storage and presentation. When using missing values, document which object owns mutable state, which caller releases resources and which failures can propagate. Names and types should express the contract without forcing a reader to inspect every implementation detail. Automated tests should verify the public behavior and avoid depending on incidental internal ordering unless that ordering is part of the contract.
type conversion
Type conversion should report invalid values and preserve semantic distinctions rather than silently coercing identifiers, dates or categories.
Type conversion should report invalid values and preserve semantic distinctions rather than silently coercing identifiers, dates or categories. The mechanism should be demonstrated with a small valid case, a boundary case and an invalid case. This reveals type conversions, empty inputs, missing values and exception behavior before the same code is placed in an AI data pipeline or web service. The practical value of type conversion appears when the program changes. A sound design permits one behavior to be replaced or extended without duplicating validation and cleanup code. Logging should identify the operation and outcome without exposing credentials or personal data and concurrent use must be supported explicitly rather than assumed from a successful single-threaded example.
merge and join
Merging combines rows by keys under one-to-one, one-to-many or many-to-many cardinality that should be validated before accepting the result.
Merging combines rows by keys under one-to-one, one-to-many or many-to-many cardinality that should be validated before accepting the result. Python’s runtime model matters: names refer to objects, operations are dispatched by type and mutability determines whether an operation changes an object or creates another one. Clear code preserves object boundaries, validates external input and uses exceptions to report conditions a caller can handle. A small example of merge and join should be traced from object or input creation through every relevant operation and return value. Include an empty or null-like case and one invalid case so the exception or boundary behavior is visible. Production use should keep external input validation, business logic, storage and presentation in separate functions or classes.
groupby and aggregation
Groupby splits rows by keys, applies aggregation or transformation and combines results while missing-key and ordering policies affect output.
Groupby splits rows by keys, applies aggregation or transformation and combines results while missing-key and ordering policies affect output. A concise Python expression is useful only when its data flow remains readable. Choose the built-in type or library abstraction that matches ordering, uniqueness, lookup, numerical or tabular requirements. Observe return values and side effects and keep transformation code separate from input, storage and presentation. When using groupby and aggregation, document which object owns mutable state, which caller releases resources and which failures can propagate. Names and types should express the contract without forcing a reader to inspect every implementation detail. Automated tests should verify the public behavior and avoid depending on incidental internal ordering unless that ordering is part of the contract.
reshape
Reshaping pivots, melts, stacks or unstacks data between wide and long organizations without changing the intended observations.
Reshaping pivots, melts, stacks or unstacks data between wide and long organizations without changing the intended observations. The mechanism should be demonstrated with a small valid case, a boundary case and an invalid case. This reveals type conversions, empty inputs, missing values and exception behavior before the same code is placed in an AI data pipeline or web service. The practical value of reshape appears when the program changes. A sound design permits one behavior to be replaced or extended without duplicating validation and cleanup code. Logging should identify the operation and outcome without exposing credentials or personal data and concurrent use must be supported explicitly rather than assumed from a successful single-threaded example.
data quality
Data quality covers validity, completeness, consistency, uniqueness, timeliness, lineage and fitness for the intended decision.
Data quality covers validity, completeness, consistency, uniqueness, timeliness, lineage and fitness for the intended decision. Python’s runtime model matters: names refer to objects, operations are dispatched by type and mutability determines whether an operation changes an object or creates another one. Clear code preserves object boundaries, validates external input and uses exceptions to report conditions a caller can handle. A small example of data quality should be traced from object or input creation through every relevant operation and return value. Include an empty or null-like case and one invalid case so the exception or boundary behavior is visible. Production use should keep external input validation, business logic, storage and presentation in separate functions or classes.
Continue learning
Related notes
Put this topic into timed practice
Open mock tests when you want full-exam pacing, or keep drilling in practice mode.