Skip to content

Instantly share code, notes, and snippets.

@wellmotta
Created June 14, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wellmotta/48563e91087bd4be4bf0ed1115bdffeb to your computer and use it in GitHub Desktop.
Save wellmotta/48563e91087bd4be4bf0ed1115bdffeb to your computer and use it in GitHub Desktop.
306912-stackoverflow created by wellmotta - https://repl.it/@wellmotta/306912-stackoverflow
import pandas as pd
def periodo(linha):
horario = linha['hora completa']
if '06:00:00' < horario < '11:59:00': return 'Manha'
elif '12:00:00' < horario < '17:59:00': return 'Tarde'
elif '18:00:00' < horario < '23:59:00': return 'Noite'
elif '00:00:00' < horario < '05:59:00': return 'Madrugada'
return ''
df = pd.DataFrame({'hora completa':['21:35:00', '22:16:00', '00:50:00', '09:30:00', '14:30:00']})
df['periodo'] = df.apply(periodo, axis=1)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment