Или, также как в base R
, используя endsWith
и substr
index <- which(endsWith(df$PlayerName, 'Q') | endsWith(df$PlayerName, 'Z'))
df$PlayerName[index] <- substr(df$PlayerName[index],
rep(1, length(index)),
nchar(df$PlayerName[index])-1L)
df
# PlayerName Score
# 1 John 75
# 2 Robert 80
# 3 Albert 67
# 4 Jeff 88
Вот сценарий, который я раньше использовал для захвата logwatch информации от моего почтового ящика. Представленный в 2008 LFNW -
#!/usr/bin/env python
''' Utility to scan my mailbox for new mesages from Logwatch on systems and then
grab useful info from the message and output a summary page.
by Brian C. Lane <bcl@brianlane.com>
'''
import os, sys, imaplib, rfc822, re, StringIO
server ='mail.brianlane.com'
username='yourusername'
password='yourpassword'
M = imaplib.IMAP4_SSL(server)
M.login(username, password)
M.select()
typ, data = M.search(None, '(UNSEEN SUBJECT "Logwatch")')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
# print 'Message %s\n%s\n' % (num, data[0][1])
match = re.search( "^(Users logging in.*?)^\w",
data[0][1],
re.MULTILINE|re.DOTALL )
if match:
file = StringIO.StringIO(data[0][1])
message = rfc822.Message(file)
print message['from']
print match.group(1).strip()
print '----'
M.close()
M.logout()
Вы забывали указывать хост IMAP и порт? Используйте что-то для эффекта:
M = imaplib.IMAP4_SSL( 'imap.gmail.com' )
или,
M = imaplib.IMAP4_SSL()
M.open( 'imap.gmail.com' )
import imaplib
# you want to connect to a server; specify which server
server= imaplib.IMAP4_SSL('imap.googlemail.com')
# after connecting, tell the server who you are
server.login('email@gmail.com', 'password')
# this will show you a list of available folders
# possibly your Inbox is called INBOX, but check the list of mailboxes
code, mailboxen= server.list()
print mailboxen
# if it's called INBOX, then…
server.select("INBOX")
Остальная часть Вашего кода кажется корректной.