This is my code. It returns only one value for each 2001, 2002, 2003 etc. I would rather it returned different ones. Would axis -1 work and if so where do I put it?
# Define a function to map the values
def set_value(row_number, assigned_value):
return assigned_value[row_number]
#Create the dictionary
year_dictionary ={'2001' : np.random.randint(1,202335), '2002' : np.random.randint(1,188846), '2003' : np.random.randint(1,175357), "2004" : np.random.randint(1,161868), "2005" : np.random.randint(1,148379), "2006": np.random.randint(1,134890), "2007" : np.random.randint(1,121401), "2008" : np.random.randint(1,107912), "2009" :np.random.randint(1,94423),"2010" :np.random.randint(1,80934), "2011" :np.random.randint(1,67445), "2012" :np.random.randint(1,53956), "2013" :np.random.randint(1,40467), "2014" :np.random.randint(1,26978), "2015" :np.random.randint(1,13489)}
# Add a new column named 'mileage'
df5['mileage'] = df5['year'].apply(set_value, args =(year_dictionary, ))
df5
Aucun commentaire:
Enregistrer un commentaire