[python] 一些資料操作 (DataFrame, list, dict) 的筆記

Hits: 205

資料操作筆記

紀錄一下自己有碰過的資料操作紀錄

list of dictionary to dictionry

想要將 list of dictionary 轉成單純的 dictionary,可透過 list comprehension + dict comprehension 達成

ld = [{'month': '10901',
  'pat_id': 'A666666666',
  'last_approve_begin_date': '20200906',
  'last_approve_end_date': '20201205'}]
dict((key, val) for k in ld for key, val in k.items())

回傳下列結果

{'month': '10901',
 'pat_idno': 'A666666666',
 'last_approve_begin_date': '20200906',
 'last_approve_end_date': '20201205'}

參考答案

About the Author

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

You may also like these