I have a pandas dataframe like this
import pandas as pd
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [4, 24, 31, 2, 3]}
DF = pd.DataFrame(data)
I need to add a new column named "key" to be filled with new values, to produce a new dataframe like this
data2 = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [4, 24, 31, 2, 3],
'keys': ["p1s4", "p1s24", "p1s31", "p1s2", "p1s3"]}
DF2 = pd.DataFrame(data2)
I wrote a code like this
DF["key"] = "p" + str(1) + "s" + str(DF["reports"])
But it doesn't work