How to use the Pandas Code Generator
- 1. Describe your fileCSV or Excel, and its name.
- 2. Tick the stepsCleaning, new columns, filters, merges, grouping, pivots, sorting and saving, with your column names.
- 3. Copy or downloadRun it with Python 3 after pip install pandas.
What the script does
Each ticked step adds a short, commented block in a sensible order. It reads the file, trims text columns, removes duplicates (optionally on chosen columns), parses dates with day-first Indian format and adds a Month column, then handles missing values (fill with a value, the mean or the median, or drop the rows). After that it adds a calculated column, filters rows (equals, comparisons, contains, is one of), merges a second file, groups with one or more aggregates or builds a pivot table with totals, sorts, shows the top rows and saves to CSV (UTF-8 with BOM for Excel) or .xlsx.
Worked example
The defaults describe a sales.csv with OrderID, Date, Region, Product, Units and Price. They produce a 38-line script with 8 steps. It trims text, drops duplicate OrderIDs, parses Date, fills missing Units with the median, adds df["Revenue"] = df["Units"] * df["Price"], sums Revenue by Region, sorts largest first and saves region_summary.csv.
How we checked it
- We ran 22 generated scripts with pandas on sample files: every step on its own, all steps together, Excel input and output, each fill and filter option, and multi-column grouping with several aggregates.
- Every script ran without errors.
- Column names must match your file exactly, including capitals and spaces.
Frequently asked questions
Do I need Jupyter?
No. Save it as a .py file and run python clean_and_analyse.py, or paste it into a Jupyter or Colab cell.
Why median for missing values?
The median isn't pulled by a few huge values, which suits money and quantity columns. Choose mean or a fixed value if that fits better.
Is the pandas code generator free?
Yes. You can open the pandas code generator, load files and set every option without signing up. When you generate code for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.