Pandas with CSV: inspect a DataFrame and make a first summary
Learn how pandas reads tabular data, what Series, DataFrame, and the index mean, and how to inspect and total a small CSV by date. The example explains missing-value handling and where in-memory analysis can become difficult.
What pandas does
pandas is a Python library for reading, inspecting, transforming, and summarizing tabular data. A small first workflow—load a CSV, check its columns, types, and missing values, then total values by date—shows how it helps. This article introduces the core data structures and a first task; joins and advanced group analysis are outside its scope.
Working with a table in Python usually means combining file input, column selection, filtering, calculations, summaries, and output. pandas provides labeled table structures and operations for these steps. It reads many file and database formats, but loading a file does not tell you what each row means or whether the data are sound. An analyst still defines the grain: for example, whether a row represents one order or one product line in an order.
Series, DataFrame, and the index
A Series is a one-dimensional labeled structure; a DataFrame is a two-dimensional structure with rows and columns. A DataFrame may look like a spreadsheet, but it is a data object operated on by explicit Python code, not a mouse-driven sheet. Selecting one column, such as df["orders"], returns a Series. The row index labels rows inside the pandas object. When a file has no supplied index, pandas commonly creates numbered labels starting at zero. These labels are not guaranteed to be durable business keys such as order IDs. Filtering or sorting may leave the original labels in place, so do not confuse displayed row order with index values.
Install and inspect before calculating
Prerequisites are an installed Python interpreter and knowing which environment you will use. Run both commands from a terminal using that environment:
python -m pip install pandas
python -c "import pandas as pd; print(pd.__version__)"The first command installs pandas into the Python environment selected by that interpreter. If the second prints a version, pandas can be imported there. If code later raises ModuleNotFoundError, check whether installation and execution used different Python environments. With a virtual environment or conda, activate it before running both commands. The pandas installation guide documents pip and conda-forge and recommends using an environment.
After reading a CSV, inspect its shape, a sample, column types, and blanks before calculating:
import pandas as pd
df = pd.read_csv("orders.csv")
print(df.shape)
print(df.head())
df.info()
print(df.isna().sum())shape gives the number of rows and columns. head displays the first five rows by default; that sample need not represent the entire file. info prints each column's type and other details, including non-missing counts when available. isna().sum() counts cells read as missing in each column. Compare these summaries with the source data because inferred types and missing markers depend on the actual values.
Add up a small order table by date
The following order quantities are invented to explain the workflow. The third date has only blank amounts. To try the file-based version, save the first block as orders.csv and run the Python code from the same working folder as the file.
day,channel,orders
2026-01-01,search,8
2026-01-01,email,4
2026-01-02,search,11
2026-01-02,email,
2026-01-03,search,
2026-01-03,email,This code converts the date column, sums orders within each date, and saves the result without adding the row index as another column:
import pandas as pd
df = pd.read_csv("orders.csv")
df["day"] = pd.to_datetime(df["day"], format="%Y-%m-%d")
daily = df.groupby("day", as_index=False)["orders"].sum(min_count=1)
print(daily)
daily.to_csv("daily_orders.csv", index=False)Grouping collects rows with the same day, applies a sum to the selected orders column, and returns one row per group. The expected totals are 12 for January 1 and 11 for January 2; January 3 remains missing. By default, the sum skips missing values, so 11 is the total of the observed amount on January 2. min_count=1 keeps January 3 missing when it has no valid numbers instead of presenting an invented zero. In real work, confirm whether a missing order count means zero or a collection failure. Recalculate the dates and totals from the input rows, then open daily_orders.csv and confirm it has only day and orders. These figures are illustrative, not real orders, and the code is not claimed to have been run or tested.
Checks before trusting the result
If dates remain strings, date ordering, range filters, and daily grouping can be confusing. read_csv supports parse_dates, but an unparseable value can leave the original column as object. When the format is known, pass it to pd.to_datetime; if conversion fails, inspect the original values and error first. A date such as 01/02/2026 is ambiguous across regional conventions, so confirm the month/day order instead of guessing.
Missing does not automatically mean zero. pandas uses different missing markers depending on data type, and many reductions skip missing values by default. Decide whether you need the sum of observed amounts or whether a business rule explicitly says an unrecorded amount is zero. Applying fillna(0) indiscriminately erases the fact that data were missing.
Without index=False, to_csv may write the pandas row index as an extra column. Unless a downstream format requires it, check that the saved file contains no meaningless number column. For FileNotFoundError, check the working folder, filename, and extension. For a date conversion error, identify inconsistent source formats and state a rule. Keep the original data before correcting values; do not hide errors by changing unknown values arbitrarily.
When pandas fits—and when to look elsewhere
pandas is useful for exploring, transforming, and summarizing tabular data that fit in memory on one Python machine. It supports many input and output formats, including CSV, Excel, SQL, and Parquet, and lets you keep analysis steps in code for reuse. Keep the code, input definition, and rules for dates or missing values together so another reader can reproduce the result.
pandas centers on in-memory data structures. As a dataset approaches available memory, intermediate copies from operations can add pressure. Start by loading only needed rows and columns and checking types. read_csv has chunksize to limit how many rows are read at once, but not every calculation can be performed independently on small chunks. Group totals that must be combined across chunks need additional design. If out-of-memory processing is essential, consider a database or distributed processing tool; base the choice on the operations and available memory, not file size alone.
References
pandas 3.1.1, 10 minutes to pandas: https://pandas.pydata.org/docs/user_guide/10min.html
pandas 3.1.1, Intro to data structures: https://pandas.pydata.org/docs/user_guide/dsintro.html
pandas 3.1.1, Installation: https://pandas.pydata.org/docs/getting_started/install.html
pandas 3.1.1, IO tools: https://pandas.pydata.org/docs/user_guide/io.html
pandas 3.1.1 API, read_csv: https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html
pandas 3.1.1 API, to_datetime: https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html
pandas 3.1.1 API, DataFrame.info: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.info.html
pandas 3.1.1, Working with missing data: https://pandas.pydata.org/docs/user_guide/missing_data.html
pandas 3.1.1, Group by: split-apply-combine: https://pandas.pydata.org/docs/user_guide/groupby.html
pandas 3.1.1 API, DataFrameGroupBy.sum: https://pandas.pydata.org/docs/reference/api/pandas.api.typing.DataFrameGroupBy.sum.html
pandas 3.1.1 API, DataFrame.to_csv: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html
pandas 3.1.1, Scaling to large datasets: https://pandas.pydata.org/docs/user_guide/scale.html