Data scientist
Senior
technical
You have been given a DataFrame with two columns, 'user_id' and 'join_date'. Some users have multiple rows with varying join dates, and others have inconsistent date formats. Describe your process for cleaning this DataFrame to ensure each user_id has a single normalized join_date in the correct format.
def clean_user_data(df):
# Convert 'join_date' to datetime and handle errors
df['join_date'] = pd.to_datetime(df['join_date'], errors='coerce')
# Drop duplicates, keeping the earliest join_date
df = df.loc[df.groupby('user_id')['join_date'].idxmin()]
return df
Trusted by 100+ professionals preparing for interviews
Trusted by 100+ professionals
50+ Company Question Banks
5+ Supported Languages
Practice More Questions Like This
Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.
Get Started Free