This doesn't work:
import pandas as pd
def myfunc():
return 'Start_{}_{}_{}_{}_End'.format(df['coverage'], df['name'],
df['reports'], df['year'])
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [4, 24, 31, 2, 3],
'coverage': [25, 94, 57, 62, 70]}
df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa',
'Yuma'])
print(df)
df['New'] = df.apply(myfunc(), axis=1)
TypeError: ("'str' object is not callable", 'occurred at index Cochice')
Can I somehow generate a new column by concatenating values for the other
columns in a row?
Expected result for column 'New' would be:
Start_Jason_2012_4_25_End
Start_Molly_2012_24_94_End
Start_Tina_2013_31_57_End
Start_Jake_2014_2_62_End
--
https://mail.python.org/mailman/listinfo/python-list