把SMSSpamCollectioncsv中labels一列的0换成ham1换成spam
可以使用Python的pandas库来实现:
import pandas as pd
# 读取csv文件
df = pd.read_csv('SMSSpamCollection.csv', sep='\t', header=None, names=['label', 'text'])
# 将0换成ham,1换成spam
df['label'] = df['label'].apply(lambda x: 'ham' if x == 0 else 'spam')
# 输出结果
print(df.head())
输出结果类似于:
label text
0 ham Go until jurong point, crazy.. Available only ...
1 ham Ok lar... Joking wif u oni...
2 spam Free entry in 2 a wkly comp to win FA Cup fina...
3 ham U dun say so early hor... U c already then say...
4 ham Nah I don't think he goes to usf, he lives aro...
``
原文地址: https://www.cveoy.top/t/topic/fP4K 著作权归作者所有。请勿转载和采集!