pandas creating a new column based on row values

codewizard at gmail.com codewizard at gmail.com
Tue Mar 28 15:43:23 EDT 2017


On Tuesday, March 28, 2017 at 3:36:57 PM UTC-4, zlju... at gmail.com wrote:
> [snip]
> 
> Can I somehow generate a new column by concatenating values for the other columns in a row?
> 

Try this (not tested):

def myfunc(row):
    return 'Start_{}_{}_{}_{}_End'.format(row['coverage'], row['name'], row['reports'], row['year']) 

df['New'] = df.apply(myfunc, axis=1)


More information about the Python-list mailing list