Reputation: 129
I have a panel for 5 years. Each person [aa_cod_fiscm]
declares his income [cc_red_lrd]
each year. I am trying to have a difference of declaration between each year and the previous one [difprev].
My code is
data["difprev"]= data.groupby(data.aa_cod_fiscm % 5).cc_red_lrd.diff()
All the variables are integers, but I get the following error
TypeError: not all arguments converted during string formatting
I don't know why. Can you help me , please?
Upvotes: 0
Views: 31
Reputation: 132
I think your issue is that the % is being evaluated as a formatter rather than a mod function because data.aa_cod_fiscm is evaluating as a str object. Maybe this is how it is stored in that attribute? You could try casting it to an int.
try this:
data["difprev"]= data.groupby(int(data.aa_cod_fiscm) % 5).cc_red_lrd.diff()
Upvotes: 1