2. Reading and inspecting data
2.3 Column types and quick stats
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
Each column has a dtype (data type). Check them all with df.dtypes:
int64→ whole numbersfloat64→ decimals, or numbers with missing valuesobject→ text
df.describe() gives quick statistics for numeric columns: count, mean, min, max and more. df.info() lists every column with its dtype and how many values are not missing.
A number column that shows as object is a warning sign: some value in it is text, such as "unknown" or "1,200".
Spot the problem
amountisint64→ good, you can do mathsamountisobject→ some values are text; clean them first
pandas marks missing values as NaN. A whole-number column with one missing value becomes float64.
How it fits together
- df.dtypes
- df.isna().sum()
- df.describe()
Step through the code
Python
import ioimport pandas as pdtext = "city,amount\nNoida,250\nDelhi,400\nPune,"df = pd.read_csv(io.StringIO(text))print(df.dtypes)print(df["amount"].mean())print(df["amount"].isna().sum())
Output
city object amount float64 dtype: object 325.0 1
Practice in pandas ✓ Solved
Print the mean of the score column.
Expected output
85.0
Reference solution
import io
import pandas as pd
text = "name,score\nAsha,80\nRavi,90"
df = pd.read_csv(io.StringIO(text))
print(df["score"].mean())
Question 1 · Easy
Which dtype does pandas use for text columns?
Question 2 · Medium
A column has 10, 20 and one empty value. Which dtype does read_csv give it?
Question 3 · Hard
An amount column shows dtype object. What is the most likely reason?
Key takeaways
Check dtypes before maths: int64 and float64 are numbers, object is text. NaN marks missing values, and mean() skips them.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in