更新於 2024/01/09閱讀時間約 6 分鐘

Rename Columns 重新命名欄位名稱_Intro to Pandas

題目敘述

題目會給定一個pandas DataFrame作為輸入,要求我們在原有的資料表上,將所有的column資料欄位名稱重新命名。

id 改名為 student_id

first 改名為 first_name

last 改名為 last_name

age 改名為 age_in_years


題目的原文敘述


測試範例

Example 1:
Input:
+----+---------+----------+-----+
| id | first | last | age |
+----+---------+----------+-----+
| 1 | Mason | King | 6 |
| 2 | Ava | Wright | 7 |
| 3 | Taylor | Hall | 16 |
| 4 | Georgia | Thompson | 18 |
| 5 | Thomas | Moore | 10 |
+----+---------+----------+-----+
Output:
+------------+------------+-----------+--------------+
| student_id | first_name | last_name | age_in_years |
+------------+------------+-----------+--------------+
| 1 | Mason | King | 6 |
| 2 | Ava | Wright | 7 |
| 3 | Taylor | Hall | 16 |
| 4 | Georgia | Thompson | 18 |
| 5 | Thomas | Moore | 10 |
+------------+------------+-----------+--------------+
Explanation:
The column names are changed accordingly.
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.