Advertisement
Guest User

noamcheck

a guest
Sep 23rd, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import pandas as pd
  2. from datetime import datetime
  3. from pytz import timezone
  4.  
  5.  
  6. def est_to_utc(date_str):
  7. datetime_obj = datetime.strptime(date_str, "%m/%d/%y %H:%M")
  8. datetime_obj_utc = datetime_obj.replace(tzinfo=timezone('UTC'))
  9. return datetime_obj_utc.strftime("%Y-%m-%d %H:%M:%S %Z%z")
  10.  
  11.  
  12. def convert_utc():
  13. cost_df = pd.read_csv("cost_1.csv")
  14. revenue_df = pd.read_csv("revenue_1.csv")
  15. cost_df["utc"] = cost_df["data_date"].apply(lambda x: est_to_utc(x))
  16. cost_df.to_csv("cost_utc.csv")
  17. revenue_df["utc"] = revenue_df["data_date"].apply(lambda x: est_to_utc(x))
  18. revenue_df.to_csv("revenue_utc.csv")
  19.  
  20.  
  21. if __name__ == '__main__':
  22. convert_utc()
  23. revenue_df = pd.read_csv("revenue_utc.csv")
  24. cost_df = pd.read_csv("cost_utc.csv")
  25. # x = revenue_df[:10].set_index('campaign_id').join(cost_df[:10]).set_index('campaign_id'))
  26. small = revenue_df[:10].merge(cost_df[:10], left_on=['campaign_id'], right_on='campaign_id').groupby({'uv'})
  27. small['uv'] = small["revenue"] / small["clicks"]
  28. small["cpc"] = small["costs"] / small["clicks"]
  29. small["roi"] = small["uv"] / small["cpc"]
  30. small["profit"] = small["revenue"] - small["cost"]
  31.  
  32. pass
  33. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement