简体   繁体   中英

Teradata Python: How to rename a column in dataframe?

How can user rename a column in teradata dataframe without converting it to Pandas dataframe?

employee = DataFrame.from_table("employee")
employee

empid       doj    dept           
13      12/04/01  ad13
7       12/02/15   ad7
7       12/02/16   ad7
5       12/02/01   ad5
5       12/02/03   ad5
15      12/04/06  ad15
15      12/04/07  ad15
15      12/04/08  ad15
5       12/02/02   ad5
7       12/02/14   ad7

Let us rename column dept to newdept

employee = employee.assign(drop_columns=True, doj=employee.doj, newdept=impressions.dept).  

User should specify all the columns that are to be included in the modified data frame. New dataframe will have only the columns mentioned in the assign. (example userid is not given in the assign call) If drop_columns=True is not given it will keep original column and add one more column with new name)

Here is the output of above call with the renamed column.

employee
        doj   newdept
0  12/04/01   ad13
1  12/04/07   ad15
2  12/04/08   ad15
3  12/02/14    ad7
4  12/02/16    ad7
5  12/02/01    ad5
6  12/02/02    ad5
7  12/02/03    ad5
8  12/02/15    ad7
9  12/04/06   ad15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM