【问题标题】:Teradata Python: How to rename a column in dataframe?Teradata Python:如何重命名数据框中的列?
【发布时间】:2020-02-23 22:57:12
【问题描述】:

用户如何重命名 teradata 数据框中的列而不将其转换为 Pandas 数据框?

【问题讨论】:

    标签: python teradata


    【解决方案1】:
    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
    

    让我们将列 dept 重命名为 newdept

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

    用户应指定要包含在修改后的数据框中的所有列。新数据框将仅包含分配中提到的列。 (在分配调用中未给出示例用户 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      相关资源
      最近更新 更多