Bird
Raised Fist0
Pandasdata~20 mins

info() for column types and nulls in Pandas - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Info() Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of info() on a DataFrame with mixed types and nulls

What is the output of the df.info() call on the following DataFrame?

Pandas
import pandas as pd
import numpy as np
df = pd.DataFrame({
    'A': [1, 2, 3, None],
    'B': ['x', 'y', None, 'z'],
    'C': [1.1, 2.2, 3.3, 4.4],
    'D': pd.to_datetime(['2023-01-01', None, '2023-01-03', '2023-01-04'])
})
df.info()
A
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   A       4 non-null      int64         
 1   B       4 non-null      object        
 2   C       4 non-null      float64       
 3   D       4 non-null      datetime64[ns]

memory usage: 256.0 bytes
B
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   A       3 non-null      float64       
 1   B       3 non-null      object        
 2   C       4 non-null      float64       
 3   D       3 non-null      datetime64[ns]

memory usage: 256.0 bytes
C
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   A       3 non-null      int64         
 1   B       3 non-null      object        
 2   C       4 non-null      float64       
 3   D       3 non-null      object        

memory usage: 256.0 bytes
D
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   A       3 non-null      float64       
 1   B       4 non-null      object        
 2   C       4 non-null      float64       
 3   D       3 non-null      datetime64[ns]

memory usage: 256.0 bytes
Attempts:
2 left
💡 Hint

Remember that null in numeric columns converts the column to float64 with nulls counted.

❓ data_output
intermediate
1:30remaining
Count of non-null values per column from info()

Given the DataFrame below, how many non-null values does column 'X' have according to df.info()?

Pandas
import pandas as pd
df = pd.DataFrame({
    'X': [10, None, 30, None, 50],
    'Y': ['a', 'b', 'c', 'd', 'e']
})
df.info()
A3
B2
C5
D4
Attempts:
2 left
💡 Hint

Count how many values in 'X' are not null.

🔧 Debug
advanced
2:00remaining
Identify the error in info() output interpretation

Which statement about the output of df.info() is incorrect?

Pandas
import pandas as pd
df = pd.DataFrame({
    'A': [1, 2, None],
    'B': ['x', None, 'z']
})
df.info()
AThe 'B' column has 3 non-null values.
BThe 'A' column has dtype 'float64' because of the null value.
CThe 'A' column has 2 non-null values.
DThe 'B' column has dtype 'object'.
Attempts:
2 left
💡 Hint

Check how many non-null values are in column 'B'.

🧠 Conceptual
advanced
1:30remaining
Understanding memory usage in info() with nulls

Why does df.info() show memory usage even when columns have null values?

ABecause memory usage only counts non-null values.
BBecause null values are ignored and do not consume memory.
CBecause pandas stores nulls as special values within the column's dtype, so memory is allocated for all rows.
DBecause info() does not calculate memory usage when nulls are present.
Attempts:
2 left
💡 Hint

Think about how pandas stores data internally.

🚀 Application
expert
2:30remaining
Using info() to detect columns with missing data

You have a DataFrame df with many columns. You want to quickly find which columns have missing values using df.info(). Which approach below correctly identifies columns with missing data?

ALook for columns where the memory usage is zero.
BLook for columns where the 'Non-Null Count' equals the total number of rows.
CLook for columns with dtype 'object' because only those can have missing values.
DLook for columns where the 'Non-Null Count' is less than the total number of rows.
Attempts:
2 left
💡 Hint

Compare non-null counts to total rows.

Practice

(1/5)
1. What does the info() method in pandas primarily show about a DataFrame?
easy
A. The number of non-null values and data types of each column
B. The first five rows of the DataFrame
C. The summary statistics like mean and median
D. The unique values in each column

Solution

  1. Step 1: Understand what info() displays

    The info() method shows the count of non-null entries and the data type for each column in a DataFrame.
  2. Step 2: Compare with other options

    The first five rows are shown by head(), summary statistics like mean and median by describe(), and unique values by methods like unique(), not info().
  3. Final Answer:

    The number of non-null values and data types of each column -> Option A
  4. Quick Check:

    info() = non-null counts + dtypes [OK]
Hint: Remember: info() shows counts and types, not data samples [OK]
Common Mistakes:
  • Confusing info() with head() or describe()
  • Thinking info() shows unique values
  • Assuming info() shows data content
2. Which of the following is the correct way to call the info() method on a pandas DataFrame named df?
easy
A. df.info()
B. info(df)
C. df.info
D. df.info[]

Solution

  1. Step 1: Recall method call syntax in pandas

    Methods are called with parentheses after the method name, so df.info() is correct.
  2. Step 2: Check other options for syntax errors

    info(df) treats info as a function, which it is not. df.info misses parentheses, so it returns the method object, not the output. df.info[] uses invalid syntax with brackets.
  3. Final Answer:

    df.info() -> Option A
  4. Quick Check:

    Method call needs parentheses: df.info() [OK]
Hint: Call methods with parentheses: df.info() not df.info [OK]
Common Mistakes:
  • Forgetting parentheses when calling methods
  • Using function syntax instead of method syntax
  • Using brackets [] instead of parentheses ()
3. Given the DataFrame df below, what will df.info() show for the column Age?
import pandas as pd
data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, None, 30]}
df = pd.DataFrame(data)
df.info()
medium
A. Age column has 3 non-null values and dtype float64
B. Age column has 2 non-null values and dtype int64
C. Age column has 2 non-null values and dtype float64
D. Age column has 3 non-null values and dtype int64

Solution

  1. Step 1: Count non-null values in Age column

    The Age column has values 25, None, and 30. None counts as null, so non-null count is 2.
  2. Step 2: Determine data type of Age column

    Because of the None, pandas converts the Age column to float64 to accommodate NaN values.
  3. Final Answer:

    Age column has 2 non-null values and dtype float64 -> Option C
  4. Quick Check:

    Nulls reduce count; None makes dtype float64 [OK]
Hint: Nulls reduce non-null count; mixed types become float [OK]
Common Mistakes:
  • Counting None as non-null
  • Assuming dtype stays int64 despite nulls
  • Ignoring dtype conversion due to nulls
4. You run df.info() but get an error: AttributeError: 'DataFrame' object has no attribute 'info'. What is the most likely cause?
medium
A. The DataFrame is empty
B. You forgot to import pandas as pd
C. You called info without parentheses
D. You overwrote the variable name df with a non-DataFrame object

Solution

  1. Step 1: Understand the error meaning

    The error says df has no attribute info, meaning df is not a DataFrame.
  2. Step 2: Identify common cause

    This usually happens if df was reassigned to something else, like a list or string, losing DataFrame methods.
  3. Final Answer:

    You overwrote the variable name df with a non-DataFrame object -> Option D
  4. Quick Check:

    AttributeError means wrong object type [OK]
Hint: Check if df is still a DataFrame before calling info() [OK]
Common Mistakes:
  • Assuming empty DataFrame causes this error
  • Thinking missing parentheses cause AttributeError
  • Ignoring variable reassignment issues
5. You have a DataFrame df with columns ['A', 'B', 'C']. Column B has many null values. You want to quickly check which columns have missing data and their types. Which code snippet best helps you decide what cleaning is needed?
hard
A. df.isnull().sum()
B. df.info()
C. df.describe()
D. df.head()

Solution

  1. Step 1: Identify what each method shows

    df.info() shows non-null counts and data types, helping spot missing data and column types.
  2. Step 2: Compare with other options

    df.describe() summarizes numeric stats but not null counts. df.isnull().sum() shows null counts but not types. df.head() shows sample rows but not summary info.
  3. Final Answer:

    df.info() -> Option B
  4. Quick Check:

    info() = null counts + types [OK]
Hint: Use info() to see null counts and types in one step [OK]
Common Mistakes:
  • Using describe() expecting null info
  • Using isnull().sum() but ignoring types
  • Using head() which shows no summary
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard