<分区>
使用 Canopy 和 Pandas,我的数据框 a 定义为:
a=pd.read_csv('text.txt')
df=pd.DataFrame(a)
df.columns=["test"]
test.txt 是一个单列文件,包含一个包含文本、数字和标点符号的字符串列表。
假设 df 看起来像:
test
%hgh&12
abc123!!!
porkyfries
我希望我的结果是:
test
hgh12
abc123
porkyfries
到目前为止的努力:
from string import punctuation /-- import punctuation list from python itself
a=pd.read_csv('text.txt')
df=pd.DataFrame(a)
df.columns=["test"] /-- define the dataframe
for p in list(punctuation):
...: df2=df.med.str.replace(p,'')
...: df2=pd.DataFrame(df2);
...: df2
上面的命令基本上只是返回相同的数据集。 感谢任何线索。
编辑:我使用 Pandas 的原因是因为数据量很大,跨越大约 100 万行,并且编码的 future 使用将应用于多达 3000 万行的列表。 长话短说,我需要以非常有效的方式清理大数据集的数据。