Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In [1]: df = pd.DataFrame([[pubA, linkA,None], [pubB, linkB,textB], [pubC, linkC,textC]], columns=['pub', 'link','text])
- In [2]: df
- Out [2]:
- pub link text
- 0 pubA linkA None
- 1 pubB linkB textB
- 2 pubC linkC textC
- def pull_text(row):
- try:
- if(pd.isnull(row['text'])):
- if row['publication' ] == 'PubA':
- print('Now serving row',row.name,'of',len(df),'Template:',row['publication'])
- sys.stdout.flush()
- #Do Template A
- time.sleep(rand)
- return article.strip()
- elif row['publication' ] == 'PubB':
- #Do Template B
- time.sleep(rand)
- return article.strip()
- elif row['publication' ] == 'PubC':
- # Do Template C
- rand = randint(2,10)
- print('Waiting', rand, 'seconds')
- sys.stdout.flush()
- time.sleep(rand)
- return result.strip()
- else:
- pass
- print('No template set for', row['publication'],':row', row.name)
- else:
- pass
- except AttributeError:
- print('error at',row.name)
- sys.stdout.flush()
- return 'error'
- df['text'] = df.apply (lambda row: pull_text (row),axis=1)
- In [3] df['text'] = df.apply (lambda row: pull_text (row),axis=1)
- In [4] df
- Out [4] pub link text
- 0 pubA linkA textA
- 1 pubB linkB None
- 2 pubC linkC None
- Out [4] pub link text
- 0 pubA linkA textA
- 1 pubB linkB textB
- 2 pubC linkC textC
Add Comment
Please, Sign In to add comment