[問題] 如何較快從key,value list建立 dict list

作者: thanksgive (乾溫)   2019-10-21 16:10:05
大家好~
現在有個需求,
當rows多的時候,會變得很慢~
目前的做法有點慢,
不曉得大家有無比較快的解法?
謝謝~
columns是欄位名稱
rows裡面每個元素都是一個tuple,該tuple個元素其值按位置剛好對應於columns名稱
columns: list of str
rows: list of tuple
def foo(columns, rows):
result = [dict(zip(columns, r)) for r in rows]
return result
作者: IAMPF (PF)   2019-10-21 17:00:00
rows多是多多 慢是多慢?
作者: jiyu520 (不要鯽魚我)   2019-10-21 18:22:00
pandas?
作者: outshaker (out)   2019-10-21 19:49:00
namedtuple 這玩意你有聽過嗎?
作者: TitanEric (泰坦)   2019-10-21 22:04:00
pandas感覺超適合

Links booklink

Contact Us: admin [ a t ] ucptt.com