Skip to main content

1667. Fix Names in a Table

Pandas

import pandas as pd


def fix_names(users: pd.DataFrame) -> pd.DataFrame:
# Use title wont enough, it transfer "meCH tSai" to "Mech Tsai"
# But the problem wants only the first char be upper, to "Mech tsai"
# users['name'] = users['name'].str.title()

users['name'] = users['name'].str.capitalize()

return users.sort_values(by='user_id')

SQL

SELECT
user_id,
CONCAT (
upper(substring(name,1,1)),
lower(right(name,length(name)-1))
) AS name
FROM Users
ORDER BY user_id ASC