Back
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?
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.
31k questions
32.8k answers
501 comments
693 users