Re: [問題] DataFrame挑選特定值後的處理
If I understand the question correctly, this is really straightforward and can be done in 1 pass. Code as following
def vip_partitioning(arr):
before = {}
after = {}
seen_vip = False
for x in arr:
if x == 'vip':
seen_vip = True
continue
if seen_vip:
if x in after:
after[x] += 1
else:
after[x] = 1
else:
if x in before:
before[x] += 1
else:
before[x] = 1
Then you have before and after which maps the
Value in the array to its occurrences.
The idea is if the array value not in the dict,
it means the occurrence is 0.
Let me know if I am understanding this correctly.
Best~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 208.91.2.4
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1476391122.A.308.html
※ 編輯: IMPOSSIBLEr (208.91.2.4), 10/14/2016 04:39:45
→
10/14 04:40, , 1F
10/14 04:40, 1F
推
10/14 10:34, , 2F
10/14 10:34, 2F
→
10/14 10:36, , 3F
10/14 10:36, 3F
→
10/14 10:36, , 4F
10/14 10:36, 4F
推
10/14 10:39, , 5F
10/14 10:39, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章