Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #Python 3
  2.  
  3.  
  4. ## Pull Closed Deals from Salesforce
  5. import pandas as pd
  6. import numpy as np
  7. from salesforce_reporting import Connection, ReportParser
  8.  
  9. #Connects to Salesforce
  10. sf = Connection(username='myemail', password='password', security_token='token')
  11.  
  12. # Pull individual Outbound Closed Deals (just rep name and $ amount for each deal)
  13. sfReportDeals = sf.get_report('00O14000008ueQW', details=True)
  14. dealsParser = ReportParser(sfReportDeals)
  15. dealsList = dealsParser.records()
  16.  
  17. #turns List into DataFrame
  18. dealsDF = pd.DataFrame(dealsList)
  19. dealsDF.columns = ['Account Owner', 'Daily']
  20.  
  21. #Changes MRC column from string to float
  22. dealsDF['Daily'] = pd.to_numeric(dealsDF['Daily'], errors='coerce').fillna(0)
  23.  
  24. #Totals by Sales Rep
  25. dealsByRepDF = dealsDF.groupby('Account Owner')
  26.  
  27. dollarsAndDeals = dealsByRepDF.agg([np.sum, np.count_nonzero]).xs('Daily', axis=1, drop_level=True).reset_index()
  28.  
  29. # Pull individual new Opportunities
  30.  
  31. oppsReport = sf.get_report('00O14000008uelo', details=True)
  32. oppsParser = ReportParser(oppsReport)
  33. oppsList = oppsParser.records()
  34. oppsDF = pd.DataFrame(oppsList)
  35.  
  36. # Column starts as 0 so renaming it Opportunity Owner
  37. oppsDF.columns = ['QLs']
  38.  
  39. # Count Opps
  40. oppsDFCount = oppsDF['QLs'].value_counts()
  41. oppsDFCount2 = pd.DataFrame(oppsDFCount)
  42. oppsDFCount2.reset_index(inplace=True)
  43. oppsDFCount2.rename(columns={'index':'Account Owner','QLs':'# of QLs'},inplace=True)
  44.  
  45.  
  46. # combine $'s and # of
  47. dollarsAndDeals.columns = ['Account Owner',"Total $'s", "# of Deals"]
  48. dollarsDealsQLs = dollarsAndDeals.merge(oppsDFCount2, on='Account Owner')
  49.  
  50. # remove column
  51. dollarsDealsQLs.columns = ['Account Owner',"Total $'s",'# of Deals','# of QLs']
  52.  
  53. # final chart of with all Outbound reps with their
  54. # (1) total number of new Opportunities
  55. # (2) total number of closed Opportunities/Deals
  56. # (3) total dollar amount of all their closed Opportunities/Deals
  57. dollarsDealsQLs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement