You can apply a function to each row in a DataFrame using df.map(function)
.
Using the DataFrame
import pandas as pd df = pd.DataFrame({'name': ['Jeff', 'Esha', 'Jia'], 'age': [30, 56, 8]})
name | age | |
---|---|---|
1 | Jeff | 30 |
2 | Esha | 56 |
3 | Jia | 8 |
Write a function, add_name_reverse_name(df)
that adds a new column, name_reverse_name
to the DataFrame which is the concatenation of the person's name and the reverse of their name.
For example, "Jeff" would be "JeffffeJ".
df = pd.DataFrame({'name': ['Jeff', 'Esha', 'Jia'], 'age': [30, 56, 8]})
name | age | |
---|---|---|
0 | Jeff | 30 |
1 | Esha | 56 |
2 | Jia | 8 |
name | age | name_reverse_name | |
---|---|---|---|
0 | Jeff | 30 | JeffffeJ |
1 | Esha | 56 | EshaahsE |
2 | Jia | 8 | JiaaiJ |