回答編集履歴
1
追記
test
CHANGED
@@ -19,3 +19,63 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
10から100ほどのファイルに分割できるような分類方法を考えてください。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
データが全部読み取れるなら、こんな感じで書けます。
|
28
|
+
|
29
|
+
```Python
|
30
|
+
|
31
|
+
from collections import Counter
|
32
|
+
|
33
|
+
import pandas as pd
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
with open('src.csv') as fin:
|
40
|
+
|
41
|
+
df = pd.read_csv(
|
42
|
+
|
43
|
+
fin, header=None, delim_whitespace=True
|
44
|
+
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
id_count = Counter()
|
50
|
+
|
51
|
+
for _, group in df.groupby(2):
|
52
|
+
|
53
|
+
group = group.sort_values(by=3, ascending=False)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
for i, (_, series) in enumerate(group.iterrows()):
|
58
|
+
|
59
|
+
idd, *_ = series
|
60
|
+
|
61
|
+
id_count[idd] += i
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
it = enumerate(id_count.most_common(), start=1)
|
66
|
+
|
67
|
+
for i, (key, value) in it:
|
68
|
+
|
69
|
+
if value == 0:
|
70
|
+
|
71
|
+
break
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
print(i, key, value)
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
pandasは書きなれていないので、多少ダサいコードだとは思います。
|