csv - Table of Top Five with Pertinent Information in Python -
i have large csv file want convert table pertinent information. select top 5 callers, include data underneath such last call description, , person received calls customer.
it this:
complaintnumber;companyname;callername;empname;callstatus;gen_code;detail code;otherdetail;calldesc;qualityissue;highpriority;received data , time; call type;count;unnamed: 14;unnamed: 15;unnamed: 16;unnamed: 17;unnamed: 18;unnamed: 19;unnamed: 20;unnamed: 21;unnamed: 22;unnamed: 23 5651;company 1;joe;rob;closed;maintenance;code 1;;sentence relatively long not long;no;1-no;6/11/2015 15:00;type 1;8;;;;;;;;;; 6642;company 1;joe;rob;closed;support;code 2;;another sentence relatively long not long;no;1-no;6/12/2015 15:00;type 2;8;;;;;;;;;; 6893;company 1;joe;rob;closed;support;code 2;;description , stuff;no;1-no;6/13/2015 15:00;type 3;8;;;;;;;;;; 4535;company 1;joe;gwen;closed;maintenance;code 4;;so , called , said such , such;no;1-no;6/14/2015 15:00;type 2;8;;;;;;;;;; 8655;company 1;joe;gwen;closed;support;code 56;;somebody needs nap apparently;no;1-no;6/15/2015 15:00;type 1;8;;;;;;;;;; 8656;company 1;joe;wendy;closed;computer;code 12;;yup typing random notes here;no;1-no;6/12/2015 15:00;type 1;8;;;;;;;;;; 8857;company 1;joe;sarah;closed;computer;code 3;;yup typing random notes here;no;1-no;6/17/2015 15:00;type 4;8;;;;;;;;;; 3348;company 1;joe;john;closed;computer;code;red;yup typing random notes here;no;1-no;6/18/2015 15:00;type 4;8;;;;;;;;;; 6679;company 2;belinda;john;closed;maintenance;code 4;;yup typing random notes here;no;1-no;6/4/2015 19:00;type 4;7;;;;;;;;;; 5510;company 2;belinda;bob;closed;support;code 1;;yup typing random notes here;no;;6/20/2015 15:00;type 4;7;;;;;;;;;; 7711;company 2;belinda;bob;closed;support;code 1;;yup typing random notes here;no;1-no;6/21/2015 12:00;type 4;7;;;;;;;;;; 6212;company 2;belinda;bob;closed;support;code 4;;yup typing random notes here;no;1-no;6/22/2015 15:00;type 2;7;;;;;;;;;; 4413;company 2;belinda;bob;closed;support;code 34;;yup typing random notes here;no;1-no;6/23/2015 5:00;type 2;7;;;;;;;;;; 1444;company 2;belinda;bob;closed;support;code 2;blue;yup typing random notes here;no;1-no;6/23/2015 15:00;type 2;7;;;;;;;;;; 5515;company 2;rodger;yolanda;closed;maintenance;code 1;;yup typing random notes here;no;1-no;6/25/2015 15:00;type 2;7;;;;;;;;;; 1756;company 3;janet;yolanda;closed;maintenance;code 2;;yup typing random notes here;no;1-no;6/26/2015 15:00;type 2;5;;;;;;;;;; 1557;company 3;janet;yolanda;closed;computer;code 4 ;;yup typing random notes here;no;1-no;6/27/2015 15:00;type 2;5;;;;;;;;;; 1238;company 3;janet;yolanda;closed;computer;code 45;purple;yup typing random notes here;no;1-no;6/28/2015 15:00;type 1;5;;;;;;;;;; 1729;company 3;richard;steve;closed;computer;code 2 ;;yup typing random notes here;no;1-no;6/29/2015 15:00;type 1;5;;;;;;;;;; 2340;company 3;richard;fred;closed;support;code 4;yellow;yup typing random notes here;no;1-no;6/30/2015 15:00;type 3;5;;;;;;;;;; 2131;company 4;pamela;rob;closed;maintenance;code 5;;yup typing random notes here;no;1-no;7/1/2015 15:00;type 3;3;;;;;;;;;; 2662;company 4;pamela;rob;closed;maintenance;code 6;;yup typing random notes here;no;1-no;7/2/2015 15:00;type 3;3;;;;;;;;;; 2833;company 4;pamela;rob;closed;maintenance;code 7;;yup typing random notes here;no;1-no;7/3/2015 15:00;type 3;3;;;;;;;;;; 2564;company 5;stan;steve;closed;computer;code 8;;yup typing random notes here;no;1-no;7/4/2015 15:00;type 3;1;;;;;;;;;; 2225;company 6;lee;steve;closed;computer;code 9;;yup typing random notes here;no;1-no;7/5/2015 15:00;type 4;1;;;;;;;;;; 1326;company 7;jackie;steven;closed;support;code 10;;yup typing random notes here;no;1-no;7/6/2015 15:00;type 1;1;;;;;;;;;; 7227;company 8;jake;rob;closed;support;code 11;;yup typing random notes here;no;1-no;7/7/2015 15:00;type 2;1;;;;;;;;;; 4228;company 9 ;steve;wendy;closed;computer;code 12;;yup typing random notes here;no;1-no;7/8/2015 15:00;type 3;1;;;;;;;;;;
i want make table has top 5 callers headings , underneath empname (whoever took calls customer), gen_code, , sentence recent (the calls have date , time received column) calldesc.
output laid out table (obviously different inputs)
i appreciate guidance on how approach problem. pseudocode fine. better if there's quick, easy way!
so far i've sorted list customers show frequency @ top of list. there don't know how recent call description or how select top five.
read table pandas dataframe:
import pandas pd filename = 'my_file.csv' df = pd.read_csv(filename, sep=';')
create pivot table: employer names vs caller names.
pivot = df.pivot_table(index='callername', columns='empname', values='complaintnumber', aggfunc='count') # clean table nans (not necessary, more beautiful): pivot.fillna(0, inplace=true)
create new column sum , save sum of each caller it:
pivot['sum'] = pivot.sum(axis=1)
sort table using sum column descending:
pivot.sort('sum', ascending=false, inplace=true)
print first 5 results of table
print(pivot[:5])
i hope wanted!
edit: can groupby original dataframe callers , select top 5 ones , display information desired.
edit2:a "pivot[:5].transpose()" bring close final table form suggested, top 5 callers table "headers"
Comments
Post a Comment