repl.it
@sidonduarte/

pandas-groupby

Python

No description

fork
loading
Files
  • main.py
main.py
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)