파이어 폭스 3를 사용하여 Faker 패키지를 사용하여 데이터 세트를 마스크하고 있습니다. 다음 주소에서 코드를 얻을 수 있습니다 : http://blog.districtdatalabs.com/a-practical-guide-to-anonymizing-datasets-with-python-faker.파이어 폭스 3를 사용하여 Faker를 사용하여 기존 데이터를 마스크하는 동안 오류가 발생했습니다.
코드 :
def anonymize_rows(rows):
"""
Rows is an iterable of dictionaries that contain name and
email fields that need to be anonymized.
"""
# Load the faker and its providers
faker = Factory.create()
# Create mappings of names & emails to faked names & emails.
c1 = defaultdict(faker.CARD_NO_ID)
c2 = defaultdict(faker.ISS_USER_NAME)
# Iterate over the rows and yield anonymized rows.
for row in rows:
# Replace the name and email fields with faked fields.
row['CARD_NO_ID'] = c1[row['CARD_NO_ID']]
row['ISS_USER_NAME'] = c2[row['ISS_USER_NAME']]
# Yield the row back to the caller
yield row
"""
The source argument is a path to a CSV file containing data to
anonymize, while target is a path to write the anonymized CSV data to.
"""
source = 'card_transaction_data_all.csv'
target = 'card_transaction_data_all_fake.csv'
with open(source, 'rU') as f:
with open(target, 'w') as o:
# Use the DictReader to easily extract fields
reader = csv.DictReader(f)
writer = csv.DictWriter(o, reader.fieldnames)
# Read and anonymize data, writing to target file.
for row in anonymize_rows(reader):
writer.writerow(row)
그러나 다음과 같이 나는 오류가 계속 :
C를 : \ Anaconda3.4 \ lib 디렉토리 \ 사이트 - 패키지 \ spyderlib \ 위젯 \ externalshell \ start_ipython_kernel.py : 1 : DeprecationWarning : 'U'모드가 #되지 않습니다 - 을 - 코딩 : UTF-8- - 역 추적 (가장 최근에 전화를 마지막) :
파일 "", 5 호선, 작가에 = fieldName에있는 "\ Anaconda3.4 \ lib 디렉토리 \ csv.py C '라인 (96), self._fieldnames = 다음 (self.reader)
csv.DictWriter (O, reader.fieldnames)
파일 파일 "C : \ Anaconda3.4 \ lib \ site-packages \ unicodecsv \ py3.py"다음 return self.reader. 다음 ()
파일 "C : \ Anaconda3.4 \ LIB \ 사이트 패키지 \ unicodecsv \ py3.py"라인 (51), F = (bs.decode (부호화, 오류 = 오류)에 대한 F 학사)
AttributeError : 'STR'개체가 어떤 속성 '디코드'
은 누군가가 나 파이썬 3의 코드를 구현 도와주세요 수가 없다? 고마워.