I have a dataframe with one column. I would like to run some computations based on the values of these columns and add new columns with column names as a string+value of column1 in a loop.
my_list = [123, 456, 789]
my_df = pd.DataFrame(my_list, columns=[‘Numbers’])
Numbers
0 123
1 456
2 789
The output of my computations based on values in the ‘Numbers’ column should be added as a separate column with column name as a string(say ‘test)with the value in the number column as the suffix. My dataframe should have columns test_123, test_456 & test_789 added. How can this be done?
I am not able to get the column names right
Prathibha K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.