Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

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

featuresA = myPandasDataFrame.columns.values + '_x'

How do I do this? Additionally, if I wanted to add x_ as a suffix, how would the solution change?

1 Answer

0 votes
by (41.4k points)
edited by

Using a list comprehension:

df.columns = [str(col) + '_x' for col in df.columns]

If you want to learn more about list comprehension in Python then you can watch this Python Tutorial.

Browse Categories

...