简体   繁体   English

Teradata Python:如何重命名 dataframe 中的列?

[英]Teradata Python: How to rename a column in dataframe?

How can user rename a column in teradata dataframe without converting it to Pandas dataframe?用户如何重命名 teradata dataframe 中的列而不将其转换为 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让我们将列 dept 重命名为 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.新的 dataframe 将只有分配中提到的列。 (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) (在分配调用中没有给出示例用户 ID)如果没有给出 drop_columns=True 它将保留原始列并添加一个新名称的列)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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