I am trying to generate some synthetic data using the below code:
df = pd.DataFrame({
'year' : pd.Series([2014, 2018]).repeat(500),
'gender': np.random.choice(['M','F'],1000,p=[0.55,0.45]),
'age': np.random.choice(range(20,65),1000),
})
df.loc[df['gender']=='M', 'income'] = ( 2000 + 550*df['age'] - 5.25*df['age']**2 ) * np.random.lognormal() * 1.035**(df['year']-2014)
It was working fine until I added in year variable, and now I am getting the following error:
ValueError: cannot reindex from a duplicate axis
I don't understand why I am getting this error as I am not doing anything with the index. What does this particular error mean, and how would I amend the code to get this to work?