Back to Chapters
Chapter Progress: 0 %0 / 7 Lessons Read
‹›

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 numbers
      • float64 → decimals, or numbers with missing values
      • object → 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

      • amount is int64 → good, you can do maths
      • amount is object → some values are text; clean them first
      Must Know:

      pandas marks missing values as NaN. A whole-number column with one missing value becomes float64.

      How it fits together

      1. df.dtypes
      2. df.isna().sum()
      3. 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

      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.

      Lesson 9 of 13

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousColumn types and quick stats
      Save your progress free for 1 month. Start free · Log in