Advertisement
KillianMills

code_result_pdd.ipynb

Nov 1st, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. #ipython notebook code_result_pdd.ipynb
  2.  
  3. import pandas as pd
  4. import numpy as np
  5. from os import listdir
  6. from os.path import isfile, join
  7.  
  8. filename = "vendor_cdrs.csv"
  9. print filename
  10.  
  11. cdrs = pd.read_csv(filename)
  12. print len(cdrs)
  13. print type(cdrs)
  14.  
  15. #print cdrs
  16. grouped = cdrs.groupby(['pdd1xx','result','i_connection','switch_id'])
  17. print type(grouped)
  18.  
  19. #[0:6]
  20.  
  21. # single out what you need
  22. trimmed = cdrs[['pdd1xx','result','i_connection','switch_id']]
  23. # trim to get prefix
  24. #trimmed['Terminating number'] = trimmed['Terminating number'].astype(str).str[0:7]
  25.  
  26.  
  27. len(trimmed.columns)
  28. trimmed
  29.  
  30. def mean_col(input_trimmed):
  31.     input_trimmed['Mean PDD'] = input_trimmed['pdd1xx'].mean()
  32.     return input_trimmed
  33.  
  34. #print trimmed.groupby(['Terminating number','Hangup code']).apply(mean_col)
  35. trimmed = trimmed.groupby(['result','i_connection','switch_id']).apply(mean_col)
  36.  
  37. # does the main logic, the counts
  38. trimmed.groupby(['result','Mean PDD','i_connection','switch_id'],as_index=False).size()
  39. #print len(trimmed.groupby(trimmed.columns.tolist(),as_index=False).size())
  40.  
  41. #trimmed.to_csv("prefix_results.csv")
  42.  
  43. trimmed.groupby(['result','Mean PDD','i_connection','switch_id'],as_index=False).size().to_csv("vendor_cdr_results_pdd.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement