Predict the Output: astype
Intermediate · Predict the output · from Pandas Data Cleaning: Missing Values, Duplicates, and Outliers
From the lesson: Pandas Data Cleaning: Missing Values, Duplicates, and Outliers
You just got a dataset from a survey. Some people skipped questions, one person typed "N/A" instead of leaving a field blank, there are three duplicate entries, and someone claims to be 900 years old. Welcome to real-world data.
Read the lessonWhat will this code print?
import pandas as pd
df = pd.DataFrame({'val': ['1', '2', '3']})
df['val'] = df['val'].astype(int)
print(df['val'].sum())import pandas as pd
df = pd.DataFrame({'val': ['1', '2', '3']})
df['val'] = df['val'].astype(int)
print(df['val'].sum())
More Pandas Data Cleaning exercises
- Count Missing ValuesIntermediate
- Fill Missing Scores with the MeanIntermediate
- Drop Rows Missing a NameIntermediate
- Remove Duplicate EmailsIntermediate
- Standardize Yes/No ResponsesIntermediate
- Remove Outlier AgesIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz