<jupyter_start><jupyter_text>DATACAMP<jupyter_code>plt.style.use('Solarize_Light2')
covid
covid['2020-03':].diff().Brazil.plot(kind='bar')
from matplotlib.dates import date2num
from datetime import datetime

# Plot your the discoveries time series
ax = covid.diff().Brazil.plot(kind='bar')

# Add a vertical red shaded region
ax.axvspan(10, 30, color='red', alpha=0.3)

# Add a horizontal green shaded region
ax.axhspan(500, 100, color='green', alpha=0.3)<jupyter_output><empty_output><jupyter_text>Plot aggregates<jupyter_code># Compute the 52 weeks rolling mean of the co2_levels DataFrame
# ma = np.log(covid.Brazil.diff() + 1).rolling(window=7).mean().reset_index()
ma = covid.Brazil.diff().rolling(window=7).mean().reset_index()

# Compute the 52 weeks rolling standard deviation of the co2_levels DataFrame
mstd = covid.Brazil.diff().rolling(window=7).std().reset_index()

# Add the upper bound column to the ma DataFrame
ma['upper'] = ma['Brazil'] + (mstd['Brazil'] * 2)

# Add the lower bound column to the ma DataFrame
ma['lower'] = ma['Brazil'] - (mstd['Brazil'] * 2)

# Plot the content of the ma DataFrame
ax = ma.set_index('index').plot(linewidth=0.8, fontsize=6)

# Specify labels, legend, and show the plot
ax.set_xlabel('Date', fontsize=10)
ax.set_ylabel('Daily New Cases (log scale)', fontsize=10)
ax.set_title('Seven Day Rolling Mean and Variance \nin Brazil from Feb to April 2020', fontsize=10)
plt.show()<jupyter_output><empty_output><jupyter_text>Summarize   Autocorrelation<jupyter_code>from statsmodels.graphics import tsaplots

# Display the autocorrelation plot of your time series
fig = tsaplots.plot_acf(ma['Brazil'].dropna(), lags=7)

# Show plot
plt.show()
### Seasonality, noise, trends
sm.tsa??
# Import statsmodels.api as sm
import statsmodels.api as sm

# Perform time series decompositon
decomposition = sm.tsa.seasonal_decompose(covid.Brazil.dropna())

# Print the seasonality component
print(decomposition.seasonal)
plt.rcParams['figure.figsize'] = 12,6
fig = decomposition.plot();
import matplotlib.dates as mdates
ax = covid.Brazil.dropna().plot(kind='bar')
# TODO: Need to make the data ticks look better
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook

years = mdates.YearLocator()   # every year
months = mdates.MonthLocator()  # every month
years_fmt = mdates.DateFormatter('%Y')

# Load a numpy structured array from yahoo csv data with fields date, open,
# close, volume, adj_close from the mpl-data/example directory.  This array
# stores the date as an np.datetime64 with a day unit ('D') in the 'date'
# column.
with cbook.get_sample_data('goog.npz') as datafile:
    data = np.load(datafile)['price_data']

fig, ax = plt.subplots()
ax.plot('date', 'adj_close', data=data)

# format the ticks
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(years_fmt)
ax.xaxis.set_minor_locator(months)

# round to nearest years.
datemin = np.datetime64(data['date'][0], 'Y')
datemax = np.datetime64(data['date'][-1], 'Y') + np.timedelta64(1, 'Y')
ax.set_xlim(datemin, datemax)

# format the coords message box
ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
ax.format_ydata = lambda x: '$%1.2f' % x  # format the price.
ax.grid(True)

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()

plt.show()
meat_mean.values
# Plot the covid data
ax = covid.Brazil.plot(fontsize=6, linewidth=1)
meat_mean = covid.Brazil.describe().transpose()
meat_mean = meat_mean.reset_index().transpose()

new_header = meat_mean.iloc[0] #grab the first row for the header
meat_mean = meat_mean[1:] #take the data less the header row
meat_mean.columns = new_header #set the header row as the df header

# Add x-axis labels
ax.set_xlabel('Date', fontsize=6)

# Add summary table information to the plot
ax.table(cellText=meat_mean.values,
         colWidths = [0.15]*len(meat_mean.columns),
         rowLabels=meat_mean.index,
         colLabels=meat_mean.columns,
         loc='top')

# Specify the fontsize and location of your legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 0.95), ncol=3, fontsize=6)

# Show plot
plt.show()
# Create a facetted graph with 2 rows and 4 columns
ma.plot(subplots=True, 
          layout=(2,4), 
          sharex=False, 
          sharey=False, 
          fontsize=2, 
          legend=False, 
          linewidth=0.2)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12620272991720743, 'fraction_numerical': 0.019243678675318864, 'mean_word_length': 4.967957276368491, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '366740', 'license': 'MIT', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1531, 'n_words': 420, 'path': 'notebooks/Brazil Time Series EDA.ipynb', 'repo_name': 'zarak/br-covid-to', 'size': '4469'}