Challenge - 5 Problems
Data Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of type checking with pandas
What is the output of this code snippet that checks data types of a pandas DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [1.5, 2.5, 3.5], 'C': ['x', 'y', 'z'] }) print(df.dtypes)
Attempts:
2 left
💡 Hint
Remember that integers default to int64 and floats to float64 in pandas.
✗ Incorrect
The DataFrame columns have types int64 for integers, float64 for floats, and object for strings.
❓ data_output
intermediate2:00remaining
Count of data types in a DataFrame
What is the output of this code that counts the number of columns by data type in a pandas DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'num1': [1, 2, 3], 'num2': [4.0, 5.0, 6.0], 'cat': ['a', 'b', 'c'], 'flag': [True, False, True] }) print(df.dtypes.value_counts())
Attempts:
2 left
💡 Hint
Check the data types of each column carefully, including booleans.
✗ Incorrect
The DataFrame has one int64 column ('num1'), one float64 column ('num2'), one object column ('cat'), and one bool column ('flag').
🔧 Debug
advanced2:00remaining
Identify the error in type checking code
What error does this code raise when trying to check data types of a list?
Data Analysis Python
data = [1, 2, 3, 4] print(data.dtypes)
Attempts:
2 left
💡 Hint
Check if Python lists have a dtypes attribute.
✗ Incorrect
Python lists do not have a dtypes attribute; only pandas DataFrames or Series have it.
🚀 Application
advanced2:00remaining
Determine data types after conversion
After converting a pandas Series to numeric with errors='coerce', what is the data type of the resulting Series?
Data Analysis Python
import pandas as pd s = pd.Series(['10', '20', 'abc', '30']) s_num = pd.to_numeric(s, errors='coerce') print(s_num.dtype)
Attempts:
2 left
💡 Hint
Non-convertible values become NaN, which forces float type.
✗ Incorrect
Because 'abc' cannot be converted to a number, it becomes NaN, which is a float, so the whole Series is float64.
🧠 Conceptual
expert2:00remaining
Understanding data types in mixed-type pandas DataFrame
Given a pandas DataFrame with columns of mixed types, which statement about the dtypes attribute is true?
Attempts:
2 left
💡 Hint
Think about how pandas stores data efficiently per column.
✗ Incorrect
Pandas assigns each column a dtype that can hold all its values, such as object for mixed types or specific numeric types.