# ---
# 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
# ---

# # EPSY 5200: Programming for Social Science Researchers
# ## Week 11: Git Demo
# ### Wednesday, November 13, 2019

import numpy.random as npr
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import scipy.stats as stats
import statsmodels.formula.api as smf

mov = pd.read_csv('tmdb_5000_movies.csv')

mov.head()

# Challenge 1: Find the descriptive stats for each numeric column

# +
# challenge 1 code here

mov[:].describe().transpose()
# -

# Challenge 2: Find which columns have missing data (and how many missing data)

# +
# challenge 2 code here

mov.isnull().sum()

# -

mov2 = mov.drop(['homepage', 'tagline'], axis = 1)

mov2.head()

sum(mov2.revenue == 0)

sum(mov2.budget == 0)

# +
# challenge 3: create mov3, which is only budget > 0 & revenue > 0

mov3 = mov2[(mov2['budget'] > 0) & (mov2['revenue'] > 0)]

# -

mov3.head()

# +
mov_plot = sns.regplot(mov3.budget, mov3.revenue).get_figure()
mov_plot.savefig('regression_plot.png')

plt.savefig('regression_plot.png')
mov_plot
# -

rev_budg = smf.ols(formula = 'revenue ~ budget', data = mov3).fit()
rev_budg

rev_budg.params

rev_budg.rsquared


rev_budg.pvalues

rev_budg.conf_int()

rev_budg.summary()

output = pd.DataFrame({'estimate': rev_budg.params, 'lowCI': rev_budg.conf_int()[0], 'highCI': rev_budg.conf_int()[1], 'pVal': rev_budg.pvalues})
output

output.to_csv('regression_table.csv')

rbr = smf.ols(formula = 'revenue ~ budget + runtime', data = mov3).fit()
rbr.summary()

sns.pairplot(mov3[['budget', 'revenue', 'runtime']], kind="reg")

mov3[mov3.runtime == mov3.runtime.max()]



StarcoderdataJupyterScriptsDedupFiltered