Skip to content

Commit fc1d6f7

Browse files
committed
Add file
1 parent cdae8e4 commit fc1d6f7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
1667. Fix Names in a Table
3+
Solved
4+
Easy
5+
Topics
6+
Companies
7+
SQL Schema
8+
Pandas Schema
9+
10+
Table: Users
11+
12+
+----------------+---------+
13+
| Column Name | Type |
14+
+----------------+---------+
15+
| user_id | int |
16+
| name | varchar |
17+
+----------------+---------+
18+
user_id is the primary key (column with unique values) for this table.
19+
This table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.
20+
21+
Write a solution to fix the names so that only the first character is uppercase and the rest are lowercase.
22+
23+
Return the result table ordered by user_id.
24+
25+
The result format is in the following example.
26+
27+
Example 1:
28+
29+
Input:
30+
Users table:
31+
+---------+-------+
32+
| user_id | name |
33+
+---------+-------+
34+
| 1 | aLice |
35+
| 2 | bOB |
36+
+---------+-------+
37+
Output:
38+
+---------+-------+
39+
| user_id | name |
40+
+---------+-------+
41+
| 1 | Alice |
42+
| 2 | Bob |
43+
+---------+-------+
44+
"""
45+
46+
import pandas as pd
47+
48+
def fix_names(users: pd.DataFrame) -> pd.DataFrame:
49+
users['name'] = users['name'].str.capitalize()
50+
return users.sort_values('user_id')

0 commit comments

Comments
 (0)