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

import pandas as pd
import os

os.getcwd()

os.chdir(os.getcwd())

movies = pd.read_csv("P4-Movie-Ratings.csv")

len(movies) #559 Rows Recorded

movies.head()

movies.columns

movies.columns=['Film', 'Genre', 'CriticalRating', 'AudienceRating','BudgetMillions', 'Year']

movies.head()

movies.info()

movies.describe().transpose()

movies.Film=movies.Film.astype('category')

movies.info()

movies.Genre=movies.Genre.astype('category') #Categories in Python are very similar to factors in R

movies.Year = movies.Year.astype('category')

movies.info()

movies.describe().transpose()

movies.head()

movies.Genre.cat.categories.tolist()

from matplotlib import pyplot as plt
import seaborn as sns
# %matplotlib inline
import warnings
warnings.filterwarnings('ignore')

# +
#Joint Plots
# -

j = sns.jointplot(data=movies,x='CriticalRating',y='AudienceRating')

j = sns.jointplot(data=movies,x='CriticalRating',y='AudienceRating',kind='hex')

# +
#<< Chart 1
# -

# ---

# +
#Histograms
# -

#already know this method:
m1 = sns.distplot(movies.AudienceRating, bins=15)

sns.set_style('darkgrid')
m2 = sns.distplot(movies.CriticalRating, bins=15)

sns.set_style("white")
n1 = plt.hist(movies.AudienceRating, bins=15)

# +
#<<< Chart 2
# -

n2 = plt.hist(movies.CriticalRating, bins=15)

# +
#<<< Chart 3
# -

# ---

# +
#Stacked Histograms

# +
plt.hist(movies[movies.Genre =='Action'].BudgetMillions, bins=15)
plt.hist(movies[movies.Genre =='Thriller'].BudgetMillions, bins=15)
plt.hist(movies[movies.Genre =='Drama'].BudgetMillions, bins=15)

plt.show()

# +
list1 = list()
mylabels = list()
for genre in movies.Genre.cat.categories:
    list1.append(movies[movies.Genre == genre].BudgetMillions)
    mylabels.append(genre)

plt.hist(list1,bins=30,stacked=True,label=mylabels)
plt.legend()
plt.show()

# +
#<< Chart 4
# -

# ---

# +
#KDE Plot Kernel-Density-Estimate Plot
# -

vis1 = sns.lmplot(data=movies,x='CriticalRating',y='AudienceRating',fit_reg=False,hue='Genre',size=7,aspect=1)

vis1 = sns.kdeplot(movies.CriticalRating,movies.AudienceRating,shade=True,shade_lowest=False,cmap='Reds')


vis1 = sns.kdeplot(movies.CriticalRating,movies.AudienceRating,shade=True,shade_lowest=False,cmap='Reds')
#Tip:
vis1 = sns.kdeplot(movies.CriticalRating,movies.AudienceRating,cmap='Reds')


# ---

# +
#Working with Subplots
# -

vis1 = sns.lmplot(data=movies,x='BudgetMillions',y='AudienceRating',fit_reg=False,hue='Genre',size=7,aspect=1)

sns.set_style('dark')
vis1 = sns.kdeplot(movies.BudgetMillions,movies.AudienceRating)

sns.set_style('dark')
vis1 = sns.kdeplot(movies.BudgetMillions,movies.CriticalRating)

f,axes = plt.subplots(2,1,figsize=(12,6),sharex=True,sharey=True)
k1 = sns.kdeplot(movies.BudgetMillions,movies.AudienceRating,ax=axes[0])
k2 = sns.kdeplot(movies.BudgetMillions,movies.CriticalRating,ax=axes[1])
k1.set(xlim=(-40,260))

# ---

# +
#ViolinPlots
# -

w = sns.boxplot(data=movies[movies.Genre=='Drama'],x='Year',y='CriticalRating')

z = sns.violinplot(data=movies[movies.Genre=='Drama'],x='Year',y='CriticalRating')

# +
#Creating a Facet Grid
# -

from matplotlib import pyplot as plt
import seaborn as sns
# %matplotlib inline
import warnings
warnings.filterwarnings('ignore')

movies.head()

sns.set_style('darkgrid')
#g = sns.FacetGrid(movies,row='Genre',hue='Genre')
g = sns.FacetGrid(movies,row='Genre',col='Year',hue='Genre')

g = sns.FacetGrid(movies,row='Genre',col='Year',hue='Genre')
g = g.map(plt.scatter,'CriticalRating','AudienceRating')

#can be populated with any type of chart. Example:Histograms
g = sns.FacetGrid(movies,row='Genre',col='Year',hue='Genre')
g = g.map(plt.hist,'BudgetMillions')

g = sns.FacetGrid(movies,row='Genre',col='Year',hue='Genre')
kws=dict(s=50,linewidth=0.5,edgecolor='black')
g = g.map(plt.scatter,'CriticalRating','AudienceRating',**kws)

# ---

#Controlling Axes and Adding Diagonals
g = sns.FacetGrid(movies,row='Genre',col='Year',hue='Genre')
kws=dict(s=50,linewidth=0.5,edgecolor='black')
g = g.map(plt.scatter,'CriticalRating','AudienceRating',**kws)
g.set(xlim=(0,100),ylim=(0,100))
for ax in g.axes.flat:
    ax.plot((0,100),(0,100),c='gray',ls='--')
g.add_legend()

# ---



StarcoderdataJupyterScriptsDedupFiltered