Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepara tabela e agrupamento de minutos adicionados #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions PreparaTabela.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#df = dataframe
#num = decide as linhas que estarão presentes na tabela preparada (num = 1 -> não remove nenhuma linha)

def preparatabela(df,num = 1):

tabela = []
for x in range(df.shape[0]):
if x%num == 0:
row = df.iloc[x]
tabela.append(row)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Você precisa criar uma nova tabela? Não é suficiente só modificar df?


df['Datetime'] = pd.to_datetime(df['Datetime'])
tabela = pd.DataFrame(tabela)
tabela.drop([0],axis=0, inplace = True)
tabela['hora'] = df['Datetime'].apply(lambda x: x.hour)
tabela['minuto'] = df['Datetime'].apply(lambda x: x.minute)
return tabela
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O que a gente quer aqui é o objeto de tipo datetime, não os valores individuais de hora e minuto.

14 changes: 14 additions & 0 deletions minutegroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#df = dataframe
#num = agrupamento em minutos do número de pessoas
def minutegroup(df,num):
tabela = preparatabela(df,num).drop(['hora', 'minuto'], axis=1)
for i in range(num,int(df.shape[0])-num,num):
if (i%num != 0):
continue
if (df.loc[i]['Refeição'] != df.loc[i-num]['Refeição']):
continue
soma = 0
for j in range(0,num):
soma += int(df.iloc[i-j,df.columns.get_loc('Num_pessoas')])
tabela.at[i,'Num_pessoas'] = soma
return tabela
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.