I have a list like this
key_fields = ['first_name', 'last_name']
And another code like this
df1 = df1.set_index(['first_name', 'last_name', df1.groupby(['first_name', 'last_name']).cumcount()])
I want to replace the hardcoded values in second line with first line
df1 = df1.set_index(key_fields + df1.groupby(key_fields).cumcount())
But it’s giving me error
numpy.core._exceptions._UFuncNoLoopError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U10'), dtype('int64')) -> None
New contributor
Ravindra Parmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.