<jupyter_start><jupyter_text>**Turma de Pós-Graduação de Ciência de Dados****Disciplina: Linguagem de Programação Python****prof: <NAME>, DSc**  **Aula 07**  **Visualização de Dados** Referências:> [1] https://plotly.com/python/plotly-express/> [2] https://en.wikipedia.org/wiki/Hans_Rosling<jupyter_code>import plotly.express as px
gapminder_df = px.data.gapminder()
gapminder_df.head()
df = px.data.gapminder().query("year==2007")
df.head()
px.strip(df, x = "lifeExp", color="continent", hover_name="country")
px.histogram(df, x = "lifeExp", color="continent", hover_name="country")
px.histogram(df, x = "lifeExp", y="pop", color="continent", hover_name="country", marginal="rug")
px.histogram(df, x = "lifeExp", y="pop", color="continent", hover_name="country", marginal="rug", facet_col="continent")
px.choropleth(df, color="lifeExp", locations = "iso_alpha", hover_name="country", height=500)
px.scatter(data_frame=gapminder_df,
           x='gdpPercap',
           y='lifeExp',
           size='pop',
           color='continent',
           title='Life Span and Wealth 1952 - 2007',
           labels={'gdpPercap':'Wealth',
                  'lifeExp':'Life Span'},
           log_x=True,
           range_y=[25,95],
           hover_name='country',
           animation_frame='year',
           height=600,
           size_max=100)<jupyter_output><empty_output><jupyter_text>**Storytelling para Finanças**<jupyter_code># Instalando o yahoo finance
!pip install yfinance --upgrade --no-cache-dir
import pandas as pd
import yfinance as yf #Instalando e importando a API no código
codigo = ['ABUD34.SA']
df = yf.download(codigo[0], 
                 start='2021-09-01', 
                 end='2021-11-01',
                 group_by="ticker"); # ";" serve para não exibir os dados
df.head()<jupyter_output><empty_output><jupyter_text>**Dicionário das variáveis:***   Date – dia.*   Open – O valor de abertura da ação no dia.*   High – Valor máximo que a ação chegou no dia.*   Low – O valor mínimo da ação no dia.*   Close – Preço de fechamento no dia.*   Adj Close – Preço de fechamento do dia ajustado.*   Volume – Volume negociado no dia.<jupyter_code>df['Close'].describe()
import seaborn as sns
sns.set_theme(style="darkgrid")
sns.distplot(df['Close'].dropna())
import plotly.io as pio
pio.renderers
import plotly.offline as py
import plotly.graph_objs as go
dados = [go.Scatter(x=df.index, y=df['Close'])]
py.iplot(dados)
# Média simples de 3 dias
df['MM_3'] = df.Close.rolling(window=3).mean()

# Média simples de 9 dias
df['MM_9'] = df.Close.rolling(window=9).mean()

# Média simples de 15 dias
df['MM_15'] = df.Close.rolling(window=15).mean()

fechamento = go.Scatter(x=df.index,
                   y=df.Close,
                   name = "ABUD34 Close",
                   line = dict(color = '#330000'),
                   opacity = 0.8)

MM_3 = go.Scatter(x=df.index,
                  y=df['MM_3'],
                  name = "Média Móvel 3 Períodos",
                  line = dict(color = '#FF8000'),
                  opacity = 0.8)

MM_9 = go.Scatter(x=df.index,
                  y=df['MM_9'],
                  name = "Média Móvel 9 Períodos",
                  line = dict(color = '#B2FF66'),
                  opacity = 0.8)

MM_15 = go.Scatter(x=df.index,
                   y=df['MM_15'],
                   name = "Média Móvel 15 Períodos",
                   line = dict(color = '#FF00FF'),
                   opacity = 0.8)

data = [fechamento, MM_3, MM_9, MM_15]

py.iplot(data)
# D Média simples de 3 dias
df['DMM_3'] = df.Close.rolling(window=3).std()
DMM_3 = go.Scatter(x=df.index,
                  y=df['DMM_3'],
                  name = "D Média Móvel 3 Períodos",
                  line = dict(color = '#FF8000'),
                  opacity = 0.8)
data2 = [DMM_3]

py.iplot(data2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14992191566892243, 'fraction_numerical': 0.03019260801665799, 'mean_word_length': 2.7023121387283235, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '157329', 'license': 'MIT', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1351, 'n_words': 304, 'path': 'Aula_07_Pos_Ciencia_De_Dados.ipynb', 'repo_name': 'rodrigosilvaluz/python_aulas_2022.1', 'size': '3860'}