# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/ricardoBatista77/Business-IA/blob/master/Aula_de_Data_Visualization.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="zOm7Mk0b0gjp" colab_type="code" colab={}
import pandas as pd

uri="https://raw.githubusercontent.com/alura-cursos/introducao-a-data-science/master/aula4.1/movies.csv"
filmes=pd.read_csv(uri)
filmes.columns=["filmeId","titulo","generos"]
filmes=filmes.set_index('filmeId')
filmes=filmes.join(filmes['generos'].str.get_dummies()).drop('generos',axis=1)
filmes['ano']=filmes['titulo'].str.extract(r'.*\((\d+)\)')
filmes=filmes.dropna()
#filmes.head()

# + id="mZWQ5mdF2q4e" colab_type="code" colab={}
uri="https://raw.githubusercontent.com/alura-cursos/introducao-a-data-science/master/aula4.1/ratings.csv"
notas=pd.read_csv(uri)
notas.columns=["usuarioId","filmesId","nota","momento"]
arredondadas=notas['nota'].round(1)
#notas.head()


# + id="Z9luumbh3TXi" colab_type="code" colab={}
medias=notas.groupby('filmesId')['nota'].mean()
filmes=filmes.join(medias).dropna().sort_values('nota',ascending=False).rename(columns={'nota': 'media'})

total=notas.groupby('filmesId')['momento'].count()
filmes=filmes.join(total)
filmes=filmes.rename(columns={'momento':'total'})
filmes=filmes.query("total > 50")
filmes['media_categoria]']=(filmes['media']).round(1).sort_values

random_filmes=filmes.sample(10)
#random_filmes.head()

# + id="l3cRISnY6uYv" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 493} outputId="fdd13593-b474-4a27-9aa3-3f79c1bd7785"
filmes.head()

# + id="CPbth0vS_Ewk" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 801} outputId="d1b53633-d52d-41ef-e14b-5cee3315b87b"
random_filmes

# + id="a4ttgb_f_q3t" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 282} outputId="fbdb06cc-5e99-4e0f-9118-b4f6ee5224e5"
notas['nota'].hist()

# + id="8VxJRZBQABFl" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 386} outputId="489edd1e-bf9f-4120-d025-f4345d591227"
notas.hist()

# + id="Y-yOjeY8AGQ2" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 282} outputId="6ba49db1-50ce-4b0a-a969-423c13f5db25"
notas['nota'].hist()

# + id="mOiE8qxvAOlo" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 265} outputId="38b3f016-0d04-4a78-91b4-560f25041077"
arredondadas.value_counts().plot.pie()

# + id="7WSvQGBDAOpF" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 71} outputId="7dd45842-e847-4884-ae0f-7aafb2d0f2b6"
import seaborn as sns

# + id="ng_B23ZeAOsQ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 296} outputId="bb1024d8-a1ff-4197-a593-96a18c17b06f"
sns.countplot(arredondadas)

# + id="gRmLq0bcAOwK" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="59729b4b-4cb7-4694-be0f-09990ba2bf0e"
import matplotlib.pyplot as plt

sns.countplot(arredondadas)
plt.title("Distribuição das notas");

# + id="Ya22PCQGR-Q_" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 296} outputId="f5a4aed5-cc06-4082-98d3-be3982f62183"
palette=sns.color_palette("Blues",10)
sns.countplot(arredondadas, palette=palette)

# + id="PmUo__NpR-ZO" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 296} outputId="2d3fea18-bcd8-4802-d5e7-2b468d14335d"
sns.distplot(filmes['media'])

# + id="mzCn4-CRR-lH" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 433} outputId="c8ab0229-2356-4412-a7ed-686faf81b186"
p=sns.barplot(data=random_filmes, x="titulo",y="media")
p.set_xticklabels(p.get_xticklabels(), rotation=45, horizontalalignment="right")
plt.title("Notas médias de 10 filmes")
plt.show()

# + id="J9QDZu1mR-qf" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 386} outputId="f2d2eb43-e71c-4e55-de82-8729c9234323"
sns.catplot(data=filmes, x="Action", y="media")

# + id="fS3PoVktAO3b" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 296} outputId="864f2ca7-a445-40d1-98a5-b5480aacdef8"
sns.distplot(filmes.query("Action==1")['media'])
sns.distplot(filmes.query("Action==0")['media'])

StarcoderdataJupyterScriptsDedupFiltered