imdb = pd.DataFrame.from_csv('imdb.csv', index_col=None)

"""
Explanation: First Step: Get the data from storage into the dataframe. 
Simple and easy method:       pd.DataFrame.from_csv
* CSV: Comma Separated Values, used in spreadsheets. Popular for import & export of smaller datasets.
* Arguments:  path-location of data file, index_col-Column to use as the row labels of the DataFrame.
End of explanation
"""


len(imdb)

imdb.shape

"""
Explanation: Now, we have the data stored as a DataFrame titled "imdb". As a simple first step, we'd like to see the structure of this DataFrame. We'll use different ways to do this ("df" is the name of an imaginary dataframe):
* Using the length function on the dataframe: "len(df)" will return the number of rows in the dataframe.
* Using the .shape property of DataFrames: "df.shape" will return a tuple showing the dimensions of the dataframe df (number of rows,number of columns).
End of explanation
"""


imdb.head(5)

"""
Explanation: But I want to look at the Data...not just funny numbers!
* Use the head method: "df.head(n)" will exhibit the first n rows of the dataframe. This is the easiest manner to get to see the structure, the names of the cloumns etc. (Highly recommended)
* Use the tail method: "df.tail(n)" will exhibit the last n rows of the dataframe.
* Enter the Dataframe's name. An excerpt of the data will be rendered in the notebook. (Not recommended)
End of explanation
"""


#Enter your code here

"""
Explanation: Please use the tail method to exhibit the last 3 rows of the imdb Dataframe
End of explanation
"""


imdb_top5=imdb.head(5) #smaller dataframe with only top 5 rows.
imdb_top5['title']     #The 'title' column of this smaller dataframe

a=imdb_top5.title

type(a)

"""
Explanation: Individual columns of the dataframe can be accessed by df.column_name or df['column_name']. However, the result is not a DataFrame, but a Series structure.
End of explanation
"""


top_years=imdb_top5.year
top_years

top_years>1950 #get boolean vector. So, only 2 movies in the top 5 were made after 1950
#smh

imdb_top5[imdb_top5.year>1950] #passing this boolean vector to the dataframe, filters the data
#rows which meet the condition (have a "True") are retained.
#rows not meeting the condition(have a "False) are removed.

"""
Explanation: Slicing/Filtering data
Culling the data based on some condition.
Running a relational quiery (<,>,==...) on any column(s) returns a boolean vector. This boolean vector can be used to filter the data.
End of explanation
"""


#type your code here
len(imdb[imdb.year>1950])

"""
Explanation: Exercise 1
Find all the movies in the data made after the year 1950.
Bonus question: how many such movies are there?
End of explanation
"""


imdb[(imdb.year>1950) & (imdb.rating>8.8)]
#Filters all movies/shows made after 1950 AND having a rating of over 8.8

"""
Explanation: If using multiple conditions in the filter, seperate each condition in brackets and use the logical operators: 
* & (AND) 
* | (or)
End of explanation
"""


imdb[(imdb.year>1950) & (imdb.rating>8.8)].sort('year')
#Filters all movies/shows made after 1950 AND having a rating of over 8.8,
#then sort this Dataframe based on the year

"""
Explanation: This output can be sorted using the sort method.
df.sort(column_name)
End of explanation
"""


#type your code here

"""
Explanation: Exercise 2
How many movies are there in the top 250 list?
End of explanation
"""


#type your code here

"""
Explanation: Exercise 3
What are the 3 top rated tv series in the top 250 list?
End of explanation
"""


#type your code here

"""
Explanation: Exercise 4
How many movies or tv series from the 80's are there in the list?
End of explanation
"""


imdb_top5=imdb.head(5)
a=imdb_top5.top_250_rank
a

a.isnull()

"""
Explanation: Dealing with nulls/NAs/NANs
Real data is always full of missing or bad entries. On a Series, a , we can use 2 methods
* a.isnull() : returns a vector exhibiting if the row is a null/NA
* a.notnull(): returns a vector exhibiting if the row is not a null/NA
End of explanation
"""


#type your code here

temp=imdb
temp.fillna(0)

"""
Explanation: Exercise 5
How many movies or tv series do not have a properly entered "top 250 rank" attribute?
End of explanation
"""


imdb[imdb.title.str.contains("Files")]

"""
Explanation: Text Mining using Dataframes
The string methods from python can be applied to Series, with the prefix "str".
So, for a Series, a, we can quiery:
* a.str.contains("target")
* a.str.startswith("target")
End of explanation
"""


#Enter your code here

"""
Explanation: Exercise 6
How many movies or tv series have names that start with "The"?
End of explanation
"""


