딕셔너리로 값 바꾸기

pandas로 효율적인 코드 작성하기

Leonidas Souliotis

PhD Candidate

딕셔너리로 단일 값 바꾸기

start_time = time.time()
names['Gender'].replace({'MALE':'BOY', 'FEMALE':'GIRL'}, 
inplace=True)
print("Time using .replace() with dictionary: {} sec".format(time.time() - start_time))
Time using .replace() with dictionary: 0.00197792053223 sec
start_time = time.time()
names['Gender'].replace('MALE', 'BOY', inplace=True)
names['Gender'].replace('FEMALE', 'GIRL', inplace=True)
print("Time using multiple .replace(): {} sec".format(time.time() - start_time))
Time using multiple .replace(): 0.00307083129883 sec
Difference in speed: 55.2555448407%
pandas로 효율적인 코드 작성하기

딕셔너리로 여러 값 바꾸기

start_time = time.time()
names.replace({'Ethnicity': {'ASIAN AND PACI': 'ASIAN', 'ASIAN AND PACIFIC ISLANDER': 'ASIAN',
                             'BLACK NON HISPANIC': 'BLACK', 'BLACK NON HISP': 'BLACK',
                             'WHITE NON HISPANIC': 'WHITE', 'WHITE NON HISP': 'WHITE'}})

print("Time using .replace() with dictionary: {} sec".format (time.time() - start_time))
Time using .replace() with dictionary: 0.0028018 sec
pandas로 효율적인 코드 작성하기

시작해 봅시다!

pandas로 효율적인 코드 작성하기

Preparing Video For Download...