import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

pd.__version__

"""
Explanation: Pandas practice on imdb movie metadata downloaded from kaggle
Source to data set: https://www.kaggle.com/deepmatrix/imdb-5000-movie-dataset
Pandas Cheatsheets: https://assets.datacamp.com/blog_assets/PandasPythonForDataScience.pdf
https://s3.amazonaws.com/quandl-static-content/Documents/Quandl+-+Pandas,+SciPy,+NumPy+Cheat+Sheet.pdf 
Getting started and checking the setup
End of explanation
"""


#read from excel file movie_metadata
imdb = pd.read_excel('movie_metadata.xls')

imdb.head(5)

#finding the number of rows and columns
imdb.shape

#finding the title of each column
imdb.columns

#finding the data types
imdb.dtypes

#descriptors for the data set
imdb.describe()

#find out if there are any null values
imdb.isnull().values.any()

#find out the number of null values in each column
imdb[imdb.columns[:]].isnull().sum()

"""
Explanation: Importing the dataset and understanding it
End of explanation
"""


imdb['language'].unique()

imdb['language'].isnull().sum()

imdb.groupby(['language'])['language'].count()

imdb_non_english = imdb.loc[imdb['language'] != 'English']

non_english_movies = imdb_non_english.groupby(['language'])['language'].count()

non_english_movies

chart = non_english_movies.plot(kind='bar', title = "Count of non english movies")
chart.autoscale(enable=True, axis='y', tight=False)

"""
Explanation: Exploring the data set
The following section contains a few simple question and answers for exploring the imdb 5000 data set
Finding out the number of unique languages the movies are in and plotting them
End of explanation
"""


imdb[imdb['imdb_score']>7.5].shape[0]

imdb_groupby_ratings = imdb.groupby(['imdb_score'])['movie_title'].count()
imdb_groupby_ratings.plot()

"""
Explanation: Find out number of movies having a rating of greater than 7.5
End of explanation
"""


imdb[imdb['duration']>180].shape[0]

imdb_groupby_duration = imdb.groupby(['duration'])['movie_title'].count()
imdb_groupby_duration.plot()

"""
Explanation: Find out number of movies having a runtime of greater than 3 hours
End of explanation
"""


