我的Spark数据帧列中有一些奇怪的字符。我想删除它。当我选择该特定列并执行.show()时,我会看到它如下从火花文本中删除特定字符
Dominant technology firm seeks ambitious, assertive, confident, headstrong salesperson to lead our organization into the next era! If you are ready to thrive in a highly competitive environment, this is the job for you. ¥ Superior oral and written communication skills¥ Extensive experience with negotiating and closing sales ¥ Outspoken ¥ Thrives in competitive environment¥ Self-reliant and able to succeed in an independent setting ¥ Manage portfolio of clients ¥ Aggressively close sales to exceed quarterly quotas ¥ Deliver expertise to clients as needed ¥ Lead the company into new markets
|
你看到的角色是¥。
我写下面的代码来从数据帧的“说明”列中删除此
from pyspark.sql.functions import udf
charReplace=udf(lambda x: x.replace('¥',''))
train_cleaned=train_triLabel.withColumn('dsescription',charReplace('description'))
train_cleaned.show(2,truncate=False)
然而它会引发错误:
File "/Users/i854319/spark/python/lib/pyspark.zip/pyspark/serializers.py", line 263, in dump_stream
vs = list(itertools.islice(iterator, batch))
File "/Users/i854319/spark/python/pyspark/sql/functions.py", line 1563, in <lambda>
func = lambda _, it: map(lambda x: returnType.toInternal(f(*x)), it)
File "<ipython-input-32-864efe6f3257>", line 3, in <lambda>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
然而,当我做到这一点上的测试字符串该字符被替换方法识别。
s='hello ¥'
print s
s.replace('¥','')
hello ¥
Out[37]:
'hello '
任何想法我错了?
AAH。多么愚蠢的错误。万分感谢! – Baktaawar