I am trying to extract elevation data from my stations information dataframe and add it to my rides dataframe.
Take df1 and df2 for example:
df1 = pd.DataFrame(
{
"Ride ID": ["100", "101", "102", "103"],
"StartStation ID": ["2", "3", "4", "1"],
"Endstation ID": ["3", "1", "2", "4"],
})
df2 = pd.DataFrame(
{
"Station ID": ["1", "2", "3", "4"],
"Elevation": ["24", "13", "10", "20"],
})
I want to extract the elevation per station (based on ID number) and add this data to the main dataset
So I end up with this:
Should I use a loop of write a function to do this?
I was thinking about a for loop with if statement but I have not managed to make it work.
Thank you
df3 = pd.DataFrame(
{
"Ride ID": ["100", "101", "102", "103"],
"StartStation ID": ["2", "3", "4", "1"],
"StartStation Elevation": ["13", "10", "20", "24"],
"Endstation ID": ["3", "1", "2", "4"],
"Endstation Elevation": ["10", "24", "13", "20"],
})