Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created February 28, 2019 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamletbatista/2d7ab40fe4f31f5e62917fb3d5d5fadc to your computer and use it in GitHub Desktop.
Save hamletbatista/2d7ab40fe4f31f5e62917fb3d5d5fadc to your computer and use it in GitHub Desktop.
Combine first
# We do a left merge to append the redirect information to our original GA dataframe.
data_redirects = data.merge(redirects, left_on="url", right_on="url", how="left")
data_redirects['true_url'] = data_redirects['redirect_url'].combine_first(data_redirects['path'])
data_redirects['true_url'] = data_redirects['true_url'].apply(lambda x: urlparse(x).path)
data_redirects['ga:date'] = pd.to_datetime(data_redirects['ga:date'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment