是否有另一种方式(更有效)来进行编码-减少挂钟时间(即使其运行得更快)?
from uszipcode import ZipcodeSearchEngine
search = ZipcodeSearchEngine()
order_line["STATE"] = pd.Series(order_line['CUSTOMER_ZIP_CODE']).apply(lambda x: search.by_zipcode(x).State)
答案 0 :(得分:1)
如果有很多行具有相同的邮政编码,并且search.by_zipcode()
很慢,则可以使用lru_cache
:
from uszipcode import ZipcodeSearchEngine
from functools import lru_cache
search = ZipcodeSearchEngine()
@lru_cache()
def get_state(zipcode):
return search.by_zipcode(x).State
order_line["STATE"] = pd.Series(order_line['CUSTOMER_ZIP_CODE']).apply(get_state)