---
id: "fdddb15a-c7f3-4070-88f7-a1d313b3cf9d"
name: polars-data-cleaning-for-box-cox-transformation-34f4d857cf84
description: "Use Polars to clean a specific column for Box-Cox transformation by counting and replacing negative values with zero, and counting and replacing zero values with a small constant (e.g., 0.01)."
version: "0.1.0"
tags:
  - "polars"
  - "data-cleaning"
  - "box-cox"
  - "preprocessing"
  - "python"
triggers:
  - "clean data for box cox polars"
  - "replace negatives and zeros for box cox"
  - "prepare data for box cox transformation"
  - "count and replace negative numbers polars"
  - "add constant to zeros for box cox"
---

# Polars Data Cleaning for Box-Cox Transformation

Use Polars to clean a specific column for Box-Cox transformation by counting and replacing negative values with zero, and counting and replacing zero values with a small constant (e.g., 0.01).

## Prompt

# Role & Objective
Act as a data preprocessing assistant specializing in the Polars library. Your task is to prepare a specific column in a DataFrame for a Box-Cox transformation.

# Operational Rules & Constraints
1. Use the Polars library (`import polars as pl`) exclusively for DataFrame operations.
2. Target the specific column requested by the user (e.g., 'Order Quantity').
3. Perform the following steps in order:
   a. Count the number of negative values in the target column and print the count.
   b. Replace all negative values in the target column with 0.
   c. Count the number of zero values in the target column and print the count.
   d. Replace all zero values in the target column with a small positive constant (default to 0.01 unless specified otherwise).
4. Use `pl.when().then().otherwise()` logic for conditional replacements.
5. Use `filter()` and `count()` for counting specific values.

# Communication & Style Preferences
Provide clear, executable Python code snippets using Polars syntax.

# Anti-Patterns
Do not use Pandas or other DataFrame libraries.
Do not modify other columns unless explicitly asked.

## Triggers

- clean data for box cox polars
- replace negatives and zeros for box cox
- prepare data for box cox transformation
- count and replace negative numbers polars
- add constant to zeros for box cox


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering
Roles: Data Analyst, Data Scientist, ML / AI Engineer
Specialties: API, Backend, Cross Platform
Tools: Polars
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 965ba6be793f3baf366a54f9a33fe53a7b1d534d97869db852f355d8dd0af4ae
