A. 'datetime64' is not a valid dtype string in astype() method
B. astype() cannot convert strings to datetime
C. The 'date' column must be numeric before conversion
D. You must use 'datetime64[ns]' instead of 'datetime64' for datetime dtype
Solution
Step 1: Understand datetime dtype format in pandas
Pandas requires the full dtype string 'datetime64[ns]' to convert to datetime.
Step 2: Identify the error cause
Using 'datetime64' alone is incomplete and causes an error; 'datetime64[ns]' is correct.
Final Answer:
You must use 'datetime64[ns]' instead of 'datetime64' for datetime dtype -> Option D
Quick Check:
Use 'datetime64[ns]' for datetime dtype [OK]
Hint: Use 'datetime64[ns]' for datetime conversion [OK]
Common Mistakes:
Using incomplete dtype string 'datetime64'
Thinking astype() can't convert strings to datetime
Believing column must be numeric before datetime conversion
5. You have a DataFrame with a column 'price' stored as strings like '$100', '$200'. You want to analyze prices numerically. Which steps correctly convert 'price' to a numeric dtype?
hard
A. Directly use astype(float) on the 'price' column
B. Remove '$' using str.replace, then convert with astype(float)
C. Use pd.to_numeric() without cleaning the '$' sign
D. Convert 'price' to int using astype('int') without changes
Solution
Step 1: Remove non-numeric characters
The '$' sign must be removed first using str.replace('$', '') to get clean numbers as strings.
Step 2: Convert cleaned strings to numeric type
After cleaning, use astype(float) to convert strings to numeric dtype for analysis.
Final Answer:
Remove '$' using str.replace, then convert with astype(float) -> Option B
Quick Check:
Clean strings before numeric conversion [OK]
Hint: Clean strings before converting to numbers [OK]
Common Mistakes:
Trying to convert strings with '$' directly
Using astype(int) without cleaning
Ignoring need to remove non-numeric characters
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.