Advertisement
Guest User

mapper

a guest
Aug 1st, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #!/usr/bin/python    
  2. # Format of each line is:
  3.  
  4.  
  5. import sys
  6. import csv
  7.  
  8.  
  9.  
  10. reader = csv.reader(sys.stdin, delimiter='\t')
  11. writer = csv.writer(sys.stdout, delimiter='\t', quotechar='"', quoting=csv.QUOTE_ALL)
  12.  
  13. next(reader, None) # skip the first line because it contains the headings of the colums
  14. for line in reader:
  15.     data = line
  16.     if len(data) == 19:
  17.         #userid1, title, tagnames, author_id, body, node_type, parent_id, abs_parent_id, added_at, score, state_string, last_edited_id, last_activity_by_id, last_activity_at, active_revision_id, extra, extra_ref_id, extra_count, marked = data
  18.        
  19.         Post_id = data[0]
  20.         Author_id = data[3]
  21.         Body_Count =len(data[4])
  22.         nodetype = data[5]
  23.         Parent_id = data[6]
  24.  
  25.        
  26.  
  27.         if nodetype == 'answer':        #to  get the results for questions only, then uncoment this line of code and adjust the indent for the line below
  28.             print "{0}\t{1}\t{2}".format(nodetype,Body_Count,Parent_id) # print it out
  29.         elif nodetype == 'question':        #to  get the results for questions only, then uncoment this line of code and adjust the indent for the line below
  30.             print "{0}\t{1}\t{2}".format(nodetype,Body_Count,Parent_id) # print it out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement