@maximum__/

CompleteGruesomeApplicationsuite

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.39920669878144355","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHBhbmRhcyBhcyBwZAoKZGF0YSA9IHBkLkRhdGFGcmFtZShbWzExLCAiYTEiLCAiYjEiXSwgWzExLCAiYTIiLCAiYjEiXSwgWzExLCAiYTMiLCAiYjEiXSwgWzEyLCAiYzEiLCAiZDEiXV0sIGNvbHVtbnM9WyJpZHgiLCAicjEiLCAicjIiXSkKZGF0YSA9IGRhdGEuc2V0X2luZGV4KCdpZHgnKQoKZGVmIHByb2Nlc3NfZ3JwKGdycCk6CiAgICByZXR1cm4ge2s6IGxpc3Qoc2V0KHYpKSBmb3Igayx2IGluIGdycC50b19kaWN0KG9yaWVudD0nbGlzdCcpLml0ZW1zKCl9CgpyZXN1bHQgPSB7a2V5OiBwcm9jZXNzX2dycChncnApIGZvciBrZXksIGdycCBpbiBkYXRhLmdyb3VwYnkobGV2ZWw9MCl9CgpwcmludChyZXN1bHQpCgojIG91dHB1dAojIHsKIyAgIDExOiB7cjE6IFthMSwgYTIsIGEzXSwgCiMgICAgICAgIHIyOiBbYjFdfSwgCiMgICAxMjoge3IxOiBbYzFdLCByMjogW2QxXX0KIyB9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pandas as pd

data = pd.DataFrame([[11, "a1", "b1"], [11, "a2", "b1"], [11, "a3", "b1"], [12, "c1", "d1"]], columns=["idx", "r1", "r2"])
data = data.set_index('idx')

def process_grp(grp):
    return {k: list(set(v)) for k,v in grp.to_dict(orient='list').items()}

result = {key: process_grp(grp) for key, grp in data.groupby(level=0)}

print(result)

# output
# {
#   11: {r1: [a1, a2, a3], 
#        r2: [b1]}, 
#   12: {r1: [c1], r2: [d1]}
# }