File size: 619 Bytes
499003f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pandas as pd


df = pd.read_csv('enron_spam_data.csv')

data = []
for index, row in df.iterrows():
    message = row['Message']
    subject = row['Subject']
    if not message or type(message) == float:
        message = subject
        subject = ''
    elif not subject or type(subject) == float:
        subject = message
        message = ''
    spam_ham = row['Spam/Ham']
    is_spam = 1 if spam_ham.lower() == 'spam' else 0
    text = (str(subject) + """

""" + str(message)).strip()
    data.append({'text': text, 'is_spam': is_spam})

df = pd.DataFrame(data)
df.to_csv('enron_spam_clean.csv', index=False)