Guest User

Untitled

a guest
Aug 31st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. In [1]: df = pd.DataFrame([[pubA, linkA,None], [pubB, linkB,textB], [pubC, linkC,textC]], columns=['pub', 'link','text])
  2.  
  3. In [2]: df
  4. Out [2]:
  5. pub link text
  6. 0 pubA linkA None
  7. 1 pubB linkB textB
  8. 2 pubC linkC textC
  9.  
  10. def pull_text(row):
  11. try:
  12. if(pd.isnull(row['text'])):
  13. if row['publication' ] == 'PubA':
  14. print('Now serving row',row.name,'of',len(df),'Template:',row['publication'])
  15. sys.stdout.flush()
  16.  
  17. #Do Template A
  18. time.sleep(rand)
  19. return article.strip()
  20.  
  21. elif row['publication' ] == 'PubB':
  22. #Do Template B
  23. time.sleep(rand)
  24. return article.strip()
  25.  
  26. elif row['publication' ] == 'PubC':
  27. # Do Template C
  28. rand = randint(2,10)
  29. print('Waiting', rand, 'seconds')
  30. sys.stdout.flush()
  31.  
  32. time.sleep(rand)
  33. return result.strip()
  34. else:
  35. pass
  36. print('No template set for', row['publication'],':row', row.name)
  37. else:
  38. pass
  39. except AttributeError:
  40. print('error at',row.name)
  41. sys.stdout.flush()
  42. return 'error'
  43.  
  44. df['text'] = df.apply (lambda row: pull_text (row),axis=1)
  45.  
  46. In [3] df['text'] = df.apply (lambda row: pull_text (row),axis=1)
  47. In [4] df
  48. Out [4] pub link text
  49. 0 pubA linkA textA
  50. 1 pubB linkB None
  51. 2 pubC linkC None
  52.  
  53. Out [4] pub link text
  54. 0 pubA linkA textA
  55. 1 pubB linkB textB
  56. 2 pubC linkC textC
Add Comment
Please, Sign In to add comment