Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ipython notebook code_result_pdd.ipynb
- import pandas as pd
- import numpy as np
- from os import listdir
- from os.path import isfile, join
- filename = "vendor_cdrs.csv"
- print filename
- cdrs = pd.read_csv(filename)
- print len(cdrs)
- print type(cdrs)
- #print cdrs
- grouped = cdrs.groupby(['pdd1xx','result','i_connection','switch_id'])
- print type(grouped)
- #[0:6]
- # single out what you need
- trimmed = cdrs[['pdd1xx','result','i_connection','switch_id']]
- # trim to get prefix
- #trimmed['Terminating number'] = trimmed['Terminating number'].astype(str).str[0:7]
- len(trimmed.columns)
- trimmed
- def mean_col(input_trimmed):
- input_trimmed['Mean PDD'] = input_trimmed['pdd1xx'].mean()
- return input_trimmed
- #print trimmed.groupby(['Terminating number','Hangup code']).apply(mean_col)
- trimmed = trimmed.groupby(['result','i_connection','switch_id']).apply(mean_col)
- # does the main logic, the counts
- trimmed.groupby(['result','Mean PDD','i_connection','switch_id'],as_index=False).size()
- #print len(trimmed.groupby(trimmed.columns.tolist(),as_index=False).size())
- #trimmed.to_csv("prefix_results.csv")
- 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