Pandas DataFrames
The core Pandas data structure — a 2D table with rows and columns
In my experience, the DataFrame is where analysts either fall in love with Python or give up on it. The ones who stick with it are the ones who understand one thing early: a DataFrame is not a spreadsheet you click around in. It is a programmable data structure — and once you treat it that way, it becomes the most powerful tool you have ever used for data work.
Every analysis I have built over twenty-plus years — sales dashboards, customer churn models, operational reports for C-suite — started the same way: load data into a DataFrame, understand its shape, fix its types, filter it, aggregate it, export it. That is the entire workflow. Everything else is detail.
The most important habit I can give you: never modify a DataFrame without first understanding what is in it. df.info() and df.describe() before you touch anything. I have seen analysts spend hours debugging wrong numbers because they skipped this step and worked on data with the wrong dtype or unexpected nulls. Two lines of code would have caught it immediately.
DataFrames support everything you need: selecting columns, filtering rows, computing new columns, sorting, grouping, merging multiple sources, and exporting to CSV or Excel. Master this one object and you will be ahead of 90% of analysts in any room.
Examples
Key Points
- ✓df.info() shows shape, column types, and null counts — run it first on any new dataset
- ✓Boolean filters: df[df["Col"] > value] — parentheses around each condition
- ✓Use & | ~ (not and or not) when combining Pandas filter conditions
- ✓.reset_index(drop=True) resets row numbers after filtering
- ✓df.copy() creates an independent copy — without it, modifications affect the original
Practice Question
You want to filter a DataFrame to rows where City is "Delhi" AND Sales > 300000. Which syntax is correct?
Related Topics
Pandas SeriesThe one-dimensional Pandas data structure — a labelled array for a single columnReading CSV and Excel FilesLoad data from CSV, Excel, and multiple sheets into Pandas DataFramesData Cleaning with PandasRename columns, fix data types, remove duplicates, and standardise messy real-world datagroupby and Pivot TablesAggregate data by category with groupby — the Pandas equivalent of Excel pivot tables