0
0
Data Analysis Pythondata~20 mins

Checking data types in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A
A      int64
B    int64
C     object
dtype: object
B
A      float64
B    float64
C     object
dtype: object
C
A      int32
B    float32
C     string
dtype: object
D
A      int64
B    float64
C     object
dtype: object
Attempts:
2 left
💡 Hint
Remember that integers default to int64 and floats to float64 in pandas.
data_output
intermediate
2: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())
A
int64      1
float64    2
object     1
dtype: int64
B
int64      2
float64    1
object     1
dtype: int64
C
int64      1
float64    1
object     1
bool       1
dtype: int64
D
int64      1
float64    1
object     2
dtype: int64
Attempts:
2 left
💡 Hint
Check the data types of each column carefully, including booleans.
🔧 Debug
advanced
2: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)
ATypeError: unsupported operand type(s) for dtypes
BAttributeError: 'list' object has no attribute 'dtypes'
CNameError: name 'dtypes' is not defined
DNo error, prints the data types of list elements
Attempts:
2 left
💡 Hint
Check if Python lists have a dtypes attribute.
🚀 Application
advanced
2: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)
Afloat64
Bint64
Cobject
Dstring
Attempts:
2 left
💡 Hint
Non-convertible values become NaN, which forces float type.
🧠 Conceptual
expert
2: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?
AEach column's dtype reflects the most specific type that can hold all its values.
BThe dtypes attribute returns a list of Python built-in types for each column.
CAll columns are automatically converted to the same dtype for consistency.
DColumns with mixed types are stored as int64 by default.
Attempts:
2 left
💡 Hint
Think about how pandas stores data efficiently per column.