Bird
Raised Fist0
Data Analysis Pythondata~10 mins

info() for column types in Data Analysis Python - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - info() for column types
Load DataFrame
↓
Call df.info()
↓
Scan each column
↓
Count non-null values
↓
Identify data type
↓
Print summary table
↓
Show memory usage
The info() method scans each column in the DataFrame, counts non-null values, identifies data types, and prints a summary including memory usage.
Execution Sample
Data Analysis Python
import pandas as pd

df = pd.DataFrame({
  'A': [1, 2, None],
  'B': ['x', 'y', 'z']
})

df.info()
This code creates a DataFrame with two columns and calls info() to show column types and non-null counts.
Execution Table
StepActionColumnNon-null CountData TypeMemory Usage
1Scan columnA2float6424 bytes
2Scan columnB3object72 bytes
3Calculate total memory---96 bytes
4Print summary table----
5End----
💡 All columns scanned and summary printed
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
non_null_counts{}{'A': 2}{'A': 2, 'B': 3}{'A': 2, 'B': 3}{'A': 2, 'B': 3}
data_types{}{'A': 'float64'}{'A': 'float64', 'B': 'object'}{'A': 'float64', 'B': 'object'}{'A': 'float64', 'B': 'object'}
memory_usage024969696
Key Moments - 2 Insights
Why does column 'A' show 2 non-null values instead of 3?
Because one value in column 'A' is None (missing), so info() counts only non-null entries as shown in execution_table rows 1 and 2.
What does the 'object' data type mean for column 'B'?
It means the column holds strings or mixed types; info() shows this as 'object' in execution_table row 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the non-null count for column 'B' at step 2?
A3
B2
C0
DNone
💡 Hint
Check the 'Non-null Count' column in execution_table row 2.
At which step is the total memory usage calculated?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Memory Usage' column and the 'Action' column in execution_table.
If column 'A' had no missing values, how would the non-null count change at step 1?
AIt would be 0
BIt would be 3
CIt would be 2
DIt would be 'object'
💡 Hint
Refer to variable_tracker for 'non_null_counts' and how missing values affect counts.
Concept Snapshot
df.info() shows a summary of a DataFrame:
- Lists each column
- Shows non-null counts
- Shows data types
- Displays memory usage
Useful to quickly check data completeness and types.
Full Transcript
The info() method in pandas scans each column of a DataFrame to count how many values are not missing (non-null). It also identifies the data type of each column, such as float64 for numbers or object for strings. Then it prints a summary table showing these counts and types, along with the memory used by the DataFrame. For example, if a column has missing values, the non-null count will be less than the total rows. This helps understand the data structure and completeness quickly.

Practice

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

Solution

  1. Step 1: Understand the purpose of info()

    The info() method is used to display concise summary of a DataFrame including data types and non-null counts.
  2. Step 2: Compare with other methods

    Methods like head() show rows, describe() shows statistics, and unique() shows unique values, so they are not correct here.
  3. Final Answer:

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

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

Solution

  1. Step 1: Recall method call syntax in Python

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

    info(df) is incorrect because info is not a standalone function; df.info misses parentheses and returns the method object; df.info[] is invalid syntax.
  3. Final Answer:

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

    Method call needs parentheses [OK]
Hint: Call methods with () after the name [OK]
Common Mistakes:
  • Forgetting parentheses when calling methods
  • Using info() as a standalone function
  • Using brackets [] instead of parentheses ()
3. Given the following DataFrame df and its info() output, what is the data type of the column Age?
import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Score': [85.5, 90.0, 88.0]}
df = pd.DataFrame(data)
df.info()
Output:
 <class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   Name    3 non-null      object 
 1   Age     3 non-null      int64  
 2   Score   3 non-null      float64
dtypes: float64(1), int64(1), object(1)
memory usage: 200.0 bytes
medium
A. float64
B. object
C. int64
D. bool

Solution

  1. Step 1: Locate the column Age in the info output

    The info output shows Age has 3 non-null values and data type int64.
  2. Step 2: Match the data type to options

    Among the options, int64 matches the data type shown for Age.
  3. Final Answer:

    int64 -> Option C
  4. Quick Check:

    Age column type = int64 [OK]
Hint: Look for column name and dtype in info() output [OK]
Common Mistakes:
  • Confusing object with string
  • Mixing float64 and int64 types
  • Ignoring the dtype column in info()
4. You run df.info() but get an error: AttributeError: 'list' object has no attribute 'info'. What is the most likely cause?
medium
A. You forgot to import pandas
B. You called info() on a list, not a DataFrame
C. You used info() without parentheses
D. The DataFrame is empty

Solution

  1. Step 1: Analyze the error message

    The error says a 'list' object has no attribute 'info', meaning the variable is a list, not a DataFrame.
  2. Step 2: Identify the cause

    Only DataFrames have the info() method. Calling it on a list causes this error.
  3. Final Answer:

    You called info() on a list, not a DataFrame -> Option B
  4. Quick Check:

    info() needs DataFrame, not list [OK]
Hint: Check variable type before calling info() [OK]
Common Mistakes:
  • Assuming info() works on lists
  • Ignoring error message details
  • Thinking empty DataFrame causes this error
5. You have a DataFrame df with 200 columns. Column 'B' has some missing values. You want to quickly check which columns have missing data and their data types. Which code snippet using info() helps you do this?
hard
A. df.info(verbose=True)
B. df.info(null_counts=True)
C. df.info(show_missing=True)
D. df.info()

Solution

  1. Step 1: Recall info() behavior on wide DataFrames

    With 200 columns (> pandas default max_info_columns=100), df.info() truncates the column list, hiding non-null counts and dtypes for most columns including potentially 'B'.
  2. Step 2: Check options

    df.info(verbose=True) forces full display of all columns' non-null counts and dtypes. Other parameters like null_counts and show_missing are invalid.
  3. Final Answer:

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

    verbose=True for full column info on large DFs [OK]
Hint: df.info(verbose=True) for full missing counts/types on wide DFs [OK]
Common Mistakes:
  • Using df.info() on wide DFs (truncates columns)
  • Using invalid parameters with info()
  • Confusing verbose with missing data display
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