0
0
Data Analysis Pythondata~20 mins

info() for column types in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Info() Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
data_output
intermediate
2:00remaining
Output of info() on DataFrame with mixed types
Given the following DataFrame, what will be the output of df.info()?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({
    'A': [1, 2, 3],
    'B': ['x', 'y', 'z'],
    'C': [1.1, 2.2, 3.3],
    'D': [True, False, True]
})
df.info()
AData columns (total 4 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null object \n 2 C 3 non-null float64\n 3 D 3 non-null bool \ndtypes: bool(1), float64(1), int64(1), object(1)\nmemory usage: 311.0 bytes
B<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 3 entries, 0 to 2\nData columns (total 4 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null object \n 2 C 3 non-null float64\n 3 D 3 non-null bool \ndtypes: bool(1), float64(1), int64(1), object(1)\nmemory usage: 311.0 bytes
CRangeIndex: 3 entries, 0 to 2\nData columns (total 4 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null object \n 2 C 3 non-null float64\n 3 D 3 non-null bool \ndtypes: bool(1), float64(1), int64(1), object(1)\nmemory usage: 311.0 bytes
DRangeIndex: 3 entries, 0 to 2\nData columns (total 4 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null string \n 2 C 3 non-null float64\n 3 D 3 non-null bool \ndtypes: bool(1), float64(1), int64(1), string(1)\nmemory usage: 311.0 bytes
Attempts:
2 left
💡 Hint
Look carefully at the default data types pandas assigns to each column based on the data.
🧠 Conceptual
intermediate
1:30remaining
Understanding info() output for missing data
If a DataFrame column has some missing values, how does info() display the count for that column?
AIt shows the count of non-null (non-missing) values in that column.
BIt shows the total number of rows regardless of missing values.
CIt shows the count of missing values in that column.
DIt shows the percentage of missing values in that column.
Attempts:
2 left
💡 Hint
Think about what 'Non-Null Count' means in the info() output.
Predict Output
advanced
2:00remaining
Output of info() after type conversion
What will be the output of df.info() after converting column 'B' to category type?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({
    'A': [10, 20, 30],
    'B': ['cat', 'dog', 'cat']
})
df['B'] = df['B'].astype('category')
df.info()
ARangeIndex: 3 entries, 0 to 2\nData columns (total 2 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null object \ndtypes: int64(1), object(1)\nmemory usage: 311.0 bytes
BRangeIndex: 3 entries, 0 to 2\nData columns (total 2 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int32 \n 1 B 3 non-null category\ndtypes: category(1), int32(1)\nmemory usage: 653.0 bytes
CRangeIndex: 3 entries, 0 to 2\nData columns (total 2 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null string \ndtypes: int64(1), string(1)\nmemory usage: 311.0 bytes
DRangeIndex: 3 entries, 0 to 2\nData columns (total 2 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 A 3 non-null int64 \n 1 B 3 non-null category\ndtypes: category(1), int64(1)\nmemory usage: 653.0 bytes
Attempts:
2 left
💡 Hint
Check what happens when you convert a column to 'category' dtype in pandas.
🔧 Debug
advanced
1:30remaining
Identify the error in info() usage
What error will occur if you try to call df.info without parentheses?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'X': [1, 2, 3]})
print(df.info)
ANo error, it prints the method object representation
BTypeError: 'method' object is not callable
CAttributeError: 'DataFrame' object has no attribute 'info'
DSyntaxError: Missing parentheses in call to 'info'
Attempts:
2 left
💡 Hint
Think about what happens when you print a method without calling it.
🚀 Application
expert
2:30remaining
Using info() to find columns with missing data
You want to find which columns in a DataFrame have missing values by using info(). Which approach below correctly identifies columns with missing data?
Data Analysis Python
import pandas as pd

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

# Which code snippet below helps identify columns with missing values using info() output?
ACheck columns where 'Dtype' is 'object' in info() output.
BCheck columns where memory usage is higher in info() output.
CCheck columns where 'Non-Null Count' is less than total rows in info() output.
DCheck columns where 'Non-Null Count' equals total rows in info() output.
Attempts:
2 left
💡 Hint
Missing values reduce the non-null count shown by info().