File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ """ 
2+ 2885. Rename Columns 
3+ Solved 
4+ Easy 
5+ Companies 
6+ Hint 
7+ DataFrame students 
8+ +-------------+--------+ 
9+ | Column Name | Type   | 
10+ +-------------+--------+ 
11+ | id          | int    | 
12+ | first       | object | 
13+ | last        | object | 
14+ | age         | int    | 
15+ +-------------+--------+ 
16+ Write a solution to rename the columns as follows: 
17+ 
18+ id to student_id 
19+ first to first_name 
20+ last to last_name 
21+ age to age_in_years 
22+ The result format is in the following example. 
23+ 
24+ Example 1: 
25+ Input: 
26+ +----+---------+----------+-----+ 
27+ | id | first   | last     | age | 
28+ +----+---------+----------+-----+ 
29+ | 1  | Mason   | King     | 6   | 
30+ | 2  | Ava     | Wright   | 7   | 
31+ | 3  | Taylor  | Hall     | 16  | 
32+ | 4  | Georgia | Thompson | 18  | 
33+ | 5  | Thomas  | Moore    | 10  | 
34+ +----+---------+----------+-----+ 
35+ Output: 
36+ +------------+------------+-----------+--------------+ 
37+ | student_id | first_name | last_name | age_in_years | 
38+ +------------+------------+-----------+--------------+ 
39+ | 1          | Mason      | King      | 6            | 
40+ | 2          | Ava        | Wright    | 7            | 
41+ | 3          | Taylor     | Hall      | 16           | 
42+ | 4          | Georgia    | Thompson  | 18           | 
43+ | 5          | Thomas     | Moore     | 10           | 
44+ +------------+------------+-----------+--------------+ 
45+ Explanation:  
46+ The column names are changed accordingly." 
47+ """ 
48+ 
49+ import  pandas  as  pd 
50+ 
51+ def  renameColumns (students : pd .DataFrame ) ->  pd .DataFrame :
52+     return  students .rename (columns =  {
53+         'id' : 'student_id' ,
54+         'first' : 'first_name' ,
55+         'last' : 'last_name' ,
56+         'age' : 'age_in_years' 
57+     })
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments