Skip to content

Instantly share code, notes, and snippets.

@fccoelho
Created January 21, 2020 20:11
Show Gist options
  • Save fccoelho/b27b8ad288f494e1358b2d064091cdf4 to your computer and use it in GitHub Desktop.
Save fccoelho/b27b8ad288f494e1358b2d064091cdf4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
# # Exercícios
# In[11]:
import pandas as pd
get_ipython().run_line_magic('pylab', 'inline')
# In[2]:
df = pd.read_csv('../Dados/AirPassengers.csv')
df
# In[3]:
df.info()
# ## 1 converter data de string para data
# In[7]:
df['Month'] = pd.to_datetime(df.Month)
df.info()
# ## 2 indexar o dataframe pela data
# In[8]:
df.set_index('Month', inplace=True)
# ## 3 fazer um gráfico do número de passageiros por mês e depois, a média por ano
# In[12]:
df.plot();
# In[15]:
df.resample('Y').mean().plot();
# In[22]:
ts = df.index[0]
ts.month_name()
# In[35]:
verão = ['June','July','August']
def é_verão(x):
return [mes in verão for mes in x.index.month_name()]
df['verao'] = df.apply(é_verão).values
df
# In[38]:
df['inverno'] = df.verao != True
# In[42]:
df[df.verao==True]['#Passengers'].plot(style='o')
df[df.verao!=True]['#Passengers'].plot(style='o')
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment