@sidonduarte/

pandas-groupby

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.49754303486530316","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IGlvCmltcG9ydCBwYW5kYXMgYXMgcGQKCnMgPSAnJycKTm9tZSxEaWEKUGVkcm8sMwpQZWRybywzClBlZHJvLDI0CkFudG9uaW8sMjQKQW50b25pbywyNApBbnRvbmlvLDI0CkNhcmxvcyw0CkNhcmxvcyw0CkNhcmxvcywyOApKb3NlLDEKSm9zZSwyCkpvc2UsMgonJycKCmRmID0gcGQucmVhZF9jc3YoaW8uU3RyaW5nSU8ocyksIHBhcnNlX2RhdGVzPVRydWUpCmRmID0gZGYuZHJvcF9kdXBsaWNhdGVzKHN1YnNldCA9IFsnTm9tZScsJ0RpYSddKQoKZ3JvdXBlZCA9IGRmLmdyb3VwYnkoWydOb21lJywgJ0RpYSddKS5zdW0oKQpwcmludChncm91cGVkLCAnXG4nKQoKCiMgc29sdcOnw6NvIGNvbSBwYW5kYXMuY29yZS5zZXJpZXMuU2VyaWVzCmxzdCA9IGRmLmdyb3VwYnkoYnk9WydOb21lJ10pWydEaWEnXS5hcHBseShsaXN0KQoKcHJpbnQoJ1NvbHXDp8OjbyBjb20gcGFuZGFzLmNvcmUuc2VyaWVzLlNlcmllcyAnKQpmb3IgaSAgaW4gbHN0Lml0ZW1zKCk6CiAgICBwcmludChpKQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import io
import pandas as pd

s = '''
Nome,Dia
Pedro,3
Pedro,3
Pedro,24
Antonio,24
Antonio,24
Antonio,24
Carlos,4
Carlos,4
Carlos,28
Jose,1
Jose,2
Jose,2
'''

df = pd.read_csv(io.StringIO(s), parse_dates=True)
df = df.drop_duplicates(subset = ['Nome','Dia'])

grouped = df.groupby(['Nome', 'Dia']).sum()
print(grouped, '\n')


# solução com pandas.core.series.Series
lst = df.groupby(by=['Nome'])['Dia'].apply(list)

print('Solução com pandas.core.series.Series ')
for i  in lst.items():
    print(i)