Pythonic way to perform urljoin operation on each value of a column in Pandas dataframe (Python 3.4)
Question: I have Pandas dataframe where one of the columns "url" contains a relative url
path. The values in this column needs to be appended with the base url to be
converted into absolute url.

I am sure looping through each row of the column is not the best approach. I
am able to do this by using Lambdas operation. However the lambdas seem a bit
magic for me and I am not so comfortable with it.

Can you recommmenda better way of doing this? Thanks.

    
    
        from urllib.parse import urljoin
        import pandas as pd
        .
        base_url = "http://www.website.com"
        .
        my_df["relatie_url"] = my_df["relatie_url"].map(lambda x : urljoin(base_url, x))
    


Answer: IIUC you can just do:

    
    
    my_df["relatie_url"] = base_url + my_df["relatie_url"]
    

This will be much quicker than calling `map`

Example:

    
    
    In [12]:
    df = pd.DataFrame({'site':['/home/index.html', '/images/src']})
    df
    
    Out[12]:
                   site
    0  /home/index.html
    1       /images/src
    
    In [13]:
    base_url = "http://www.website.com"
    df['site'] = base_url + df['site']
    df
    
    Out[13]:
                                         site
    0  http://www.website.com/home/index.html
    1       http://www.website.com/images/src
    

