Sub topic 4
Reading the output of info
DataFrame.info() answers three questions in one call: how many rows and columns the table has, what type each column holds, and how many values in each column are present. This chapter assumes you can build a DataFrame and have used head and shape. It covers every part of the output, the parameters that change it, and the mistakes people make when reading it.
Running info on a small table
Start with the DataFrame from earlier in the tutorial. One age is missing on purpose.
import numpy as np
import pandas as pd
df = pd.DataFrame({
"name": ["Ana", "Ben", "Cleo", "Dev", "Eli"],
"age": [34, 28, np.nan, 45, 39],
"city": ["Lima", "Oslo", "Lima", "Pune", "Oslo"],
"salary": [52000, 48000, 61000, 75000, 58000],
})
df.info()On pandas 2.x the console shows this:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 5 non-null object
1 age 4 non-null float64
2 city 5 non-null object
3 salary 5 non-null int64
dtypes: float64(1), int64(1), object(2)
memory usage: 292.0+ bytesinfo prints straight to the console and returns None. Writing print(df.info()) therefore prints the report followed by the word None. Call it bare.
The parts of the report
| Line or column | What it tells you |
|---|---|
| `<class ...>` | The object type. It confirms you hold a DataFrame and not a Series or something else. |
| `RangeIndex: 5 entries, 0 to 4` | The index type, the row count, and the first and last labels. |
| `Data columns (total 4 columns)` | The column count. |
| `#` | The column's position, starting at 0. |
| `Non-Null Count` | How many values in the column are not missing. |
| `Dtype` | The data type pandas stores for the column. |
| `dtypes: ...` | How many columns share each dtype. |
| `memory usage` | An estimate of the memory the object occupies. |
The index line
A freshly built DataFrame has a RangeIndex, which stores only a start, stop, and step. If you filter rows or set a column as the index, this line changes. For example, it may read Index: 3 entries, 0 to 4. The entry count is still the number of rows. The labels after to are the first and last index labels, not a count. After a filter, "0 to 4" can describe only 3 rows.
Non-null counts and missing values
Compare each column's non-null count with the row count. In the example, age has 4 non-null values out of 5 entries, so one value is missing. The other columns are complete.
A missing value here means NaN, None, or NaT (the missing marker for datetimes). info counts nothing else as missing. A placeholder such as "", "N/A", "unknown", or -1 is a real value as far as pandas is concerned, so it counts as non-null. A column can show a full count and still hold unusable entries.
You can reproduce the counts without info:
print(len(df)) # 5 rows
print(df.count()) # non-null count per column
print(len(df) - df.count()) # missing count per column
print(df.isna().sum()) # same missing countscount() matches the "Non-Null Count" column, and isna().sum() matches the missing counts. Use these when you need the numbers as data rather than as printed text.
The Dtype column
The Dtype column shows how pandas stores each column, and this matters for what you can do with it.
int64andfloat64are numeric columns. An integer column that containsNaNis converted tofloat64, because the default integer type cannot hold a missing value. That is whyageisfloat64even though the ages look like whole numbers.objectusually means text. It can also mean a column of mixed Python objects, such as numbers and strings together.datetime64[ns],bool, andcategoryappear when a column has been parsed or converted to those types.
In pandas 3.0 and later, text columns default to a dedicated string dtype. It displays as str. Older versions show object. The reading skill is the same.
The summary line dtypes: float64(1), int64(1), object(2) is a quick check. If you expected four numeric columns and see object(2), two columns were not parsed as numbers.
Options that change the output
info accepts several parameters.
import io
df.info(verbose=False) # summary only, no per-column table
df.info(show_counts=False) # hide the Non-Null Count column
df.info(memory_usage=False) # skip the memory line
buffer = io.StringIO()
df.info(buf=buffer) # write the report to a buffer
report = buffer.getvalue()
print(report.splitlines()[1]) # RangeIndex: 5 entries, 0 to 4verbose=Falseis useful for very wide tables. With the default, pandas switches to the short form on its own when a table has more than 100 columns (thedisplay.max_info_columnsoption). Passverbose=Trueto force the full table. Passmax_colsto set the threshold for one call.show_countscontrols the non-null column. Hiding it makes the call cheaper on large tables, because counting requires a pass over the data.bufredirects the report to any writable object. This is the way to captureinfooutput as a string, since the method returnsNone.
Memory usage
The last line is an estimate of the memory the DataFrame uses. By default, info counts only the memory of the arrays themselves. For object columns, that is the pointers to Python objects, and it excludes the objects. The trailing + in 292.0+ bytes warns that this figure is a lower bound.
Pass memory_usage="deep" to measure the actual objects:
df.info(memory_usage="deep")The + disappears and the number grows, because every string is now measured. Deep mode is slower on large tables. Use it when a table holds many text columns and you want a realistic figure.
A common use of this figure is to compare storage choices. Text columns with few distinct values shrink a lot as category:
big = pd.DataFrame({"city": ["Lima", "Oslo", "Pune"] * 100_000})
as_object = big["city"].memory_usage(deep=True)
as_category = big["city"].astype("category").memory_usage(deep=True)
print(as_category < as_object) # TrueDo this comparison on realistic data. On a five-row table the saving is negligible.
Reading the report as a checklist
Read the output from top to bottom and ask one question at each line.
Common errors when reading info
Trusting a full count
A count equal to the row count means no NaN. It does not mean the data is clean. Placeholder strings are counted as present. Follow up with df["col"].value_counts() on columns where you suspect them.
Numbers stored as text
A column of prices such as "1,200" loads as object, because the comma stops parsing. info shows object where you expected a number, and later arithmetic fails or concatenates strings. The report is where you catch this:
prices = pd.DataFrame({"price": ["1,200", "950", "2,400"]})
prices.info()
prices["price"] = prices["price"].str.replace(",", "").astype("int64")
prices.info()The first report shows object. The second shows int64.
Integer columns that became float
A whole-number column shown as float64 often hides a missing value. If you want integers and missing values together, use the nullable Int64 type (capital I):
df["age"] = df["age"].astype("Int64")
df.info()The age row now reads 4 non-null with dtype Int64, and the values print as integers with <NA> for the missing one.
Misreading memory
The default figure is a floor for tables with text. A table that reports 50 MB in default mode may use far more. Do not size a machine from the shallow number alone.
Expecting a value
info returns None, so you cannot store the result or index into it. To work with the facts programmatically, use df.dtypes, df.count(), df.shape, and df.memory_usage(deep=True).
Exercises
Exercise
A DataFrame loaded from a CSV shows RangeIndex: 1000 entries, 0 to 999. The signup_date column reads 950 non-null with dtype object, and visits reads 1000 non-null with dtype float64. State what each line tells you, and name one reason visits could be float even though visit counts are whole numbers.
Show answer
signup_date has 50 missing values out of 1000 rows, and it was not parsed as a date, since object means it is stored as text. visits has no missing values. It is float64 most likely because the column held a missing value at parse time and was later filled, or because the file stored values like 3.0. Another possible cause is an earlier step that introduced NaN and was then filled. A nullable Int64 conversion restores integers if the column has no stray non-integer values.
Exercise
You call result = df.info() and then print(result). What is printed in total, and how would you capture the report as a string instead?
Show answer
The report prints once, when df.info() runs. Then print(result) prints None, because info returns None. To capture the report, create buffer = io.StringIO(), call df.info(buf=buffer), and read buffer.getvalue().