How to add a suffix (or prefix) to each column name?

前端 未结 6 2100
-上瘾入骨i
-上瘾入骨i 2020-11-28 23:12

I want to add _x suffix to each column name like so:

featuresA = myPandasDataFrame.columns.values + \'_x\'

How do I do this? A

6条回答
  •  一向
    一向 (楼主)
    2020-11-28 23:49

    The following is the nicest way to add suffix in my opinion.

    df = df.add_suffix('_some_suffix')
    

    As it is a function that is called on DataFrame and returns DataFrame - you can use it in chain of the calls.

提交回复
热议问题