LeetCode-in-Java

3374. First Letter Capitalization II

Hard

SQL Schema

Table: user_content

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| content_id  | int     |
| content_text| varchar |
+-------------+---------+ content_id is the unique key for this table. Each row contains a unique ID and the corresponding text content. 

Write a solution to transform the text in the content_text column by applying the following rules:

Return the result table that includes both the original content_text and the modified text following the above rules.

The result format is in the following example.

Example:

Input:

user_content table:

+------------+---------------------------------+
| content_id | content_text                    |
+------------+---------------------------------+
| 1          | hello world of SQL              |
| 2          | the QUICK-brown fox             |
| 3          | modern-day DATA science         |
| 4          | web-based FRONT-end development |
+------------+---------------------------------+ 

Output:

+------------+---------------------------------+---------------------------------+
| content_id | original_text                   | converted_text                  |
+------------+---------------------------------+---------------------------------+
| 1          | hello world of SQL              | Hello World Of Sql              |
| 2          | the QUICK-brown fox             | The Quick-Brown Fox             |
| 3          | modern-day DATA science         | Modern-Day Data Science         |
| 4          | web-based FRONT-end development | Web-Based Front-End Development |
+------------+---------------------------------+---------------------------------+ 

Explanation:

Solution

import pandas as pd

def capitalize_content(user_content):
    user_content['converted_text'] = (user_content.content_text.apply(lambda x: x.title()))
    return user_content.rename(columns={'content_text': 'original_text'})