Challenge - 5 Problems
Numeric Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of dtype after arithmetic operation
What is the dtype of the 'result' column after adding an int64 and a float64 column in pandas?
Pandas
import pandas as pd df = pd.DataFrame({ 'A': pd.Series([1, 2, 3], dtype='int64'), 'B': pd.Series([0.1, 0.2, 0.3], dtype='float64') }) df['result'] = df['A'] + df['B'] print(df['result'].dtype)
Attempts:
2 left
💡 Hint
Think about what happens when you add integers and floats in pandas columns.
✗ Incorrect
When you add an int64 column to a float64 column, pandas upcasts the result to float64 to preserve decimal values.
❓ data_output
intermediate2:00remaining
Count of float64 values after conversion
After converting a pandas Series of integers to float64, how many values remain float64?
Pandas
import pandas as pd s = pd.Series([10, 20, 30], dtype='int64') s = s.astype('float64') print(s.dtype) print(s.count())
Attempts:
2 left
💡 Hint
Check the dtype after astype conversion and count of non-null values.
✗ Incorrect
The Series is converted to float64 dtype and all 3 values remain non-null, so count is 3.
🔧 Debug
advanced2:00remaining
Identify the error in dtype conversion
What error will this code raise when converting a string column with non-numeric values to int64?
Pandas
import pandas as pd df = pd.DataFrame({'col': ['1', '2', 'three']}) df['col'] = df['col'].astype('int64')
Attempts:
2 left
💡 Hint
Check what happens when a non-numeric string is converted to int.
✗ Incorrect
The string 'three' cannot be converted to int64, so pandas raises a ValueError.
❓ visualization
advanced2:00remaining
Visualizing dtype distribution in DataFrame
Which code snippet correctly plots the count of int64 and float64 columns in a DataFrame?
Pandas
import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({ 'int_col': pd.Series([1, 2, 3], dtype='int64'), 'float_col': pd.Series([1.1, 2.2, 3.3], dtype='float64'), 'str_col': ['a', 'b', 'c'] })
Attempts:
2 left
💡 Hint
Use dtypes and value_counts to count column types before plotting.
✗ Incorrect
Option D counts the number of columns by dtype and plots only int64 and float64 counts correctly.
🧠 Conceptual
expert2:00remaining
Memory usage difference between int64 and float64
Which statement about memory usage of int64 vs float64 columns in pandas is correct?
Attempts:
2 left
💡 Hint
Check the size in bytes of int64 and float64 types.
✗ Incorrect
Both int64 and float64 use 8 bytes per element, so their memory usage per element is the same.