I am new to Python so apologies if it comes across as a really easy question. I have the following example dataframe below (the real one has thousands of rows)
df = {'City': ['London','Tokyo','London','Paris','Paris','London','Tokyo','Tokyo', 'Paris','Berlin','Berlin','Berlin'],
'Code': ['367','812','367','964','964','BN611','812','Y366','Z167','L715','412','L715']}
df = pd.DataFrame(data=df)
What I am trying to do is substitute all the instances where the code for a city starts with a letter with its numeric equivalent (for example, the code for each line where London appears should always be 367 instead of 367 and BN611).
Is there a way to do this easily without having to write a code for each city separately? The dataframe I have contains a few hundred more cities and I will need to apply this to every one of them. The codes for each city are always the same (for example London always has the code 367 and BN611, etc.)
Thank you