<jupyter_start><jupyter_text>Task 1: To get the IMDB code & URL's  Before starting the analysis I explored the data a bit and noted some factors that affected our analysis. One of them was that in some cases the movie title was given as **PK(film)** and while searching no result was shown for such cases and similar thing happened for cases like **Ghajini(2008 film)** and **Baby(2015 Hindi Film)**. So, using sql and excel I edited the data a bit which can be found in the **Bollywood_Movie_Dataset_Cleaned.xlsx** which i'll be submitting with this file. Also, there were some unwanted symbols like **Gangs of Wasseypur *â€“* Part 2** which i filtered out as well. As a result i was able to find the data of *3972/4000* movies on imdb while earlier this data was limited to just *2800/4000*.<jupyter_code>from imdb import IMDb
import pandas as pd 
from requests import get
mm = IMDb()
db = pd.read_csv('Dataset/Bollywood_Movies_Dataset_Cleaned.csv')
db.head()
movie_list = db['Movie Title'].tolist()
movie_list[686]
url_list = []
imdb_id = []
for name in movie_list:
  movies = mm.search_movie(name)
  try:
    id = movies[0].movieID
    imdb_id.append(id)
    url_list.append('https://www.imdb.com/title/tt'+str(id))
  except:
    imdb_id.append('NaN')
    url_list.append('Url not found!!')
len(url_list)
db['url'] = url_list
db['imdb_id'] = imdb_id
db.count()
db.head()
db = db[db.url != 'Url not found!!']
db.count()
db.to_csv('Outputs/movies_id_url.csv', index=False)<jupyter_output><empty_output><jupyter_text>Task 2: To make a new Database containing requested colomns<jupyter_code>new_db = pd.read_csv('Outputs/movies_id_url.csv')
imdb_id = new_db['imdb_id'].tolist()
def create_db(id):
  data = mm.get_movie(id)

  try:
    release = str(data.get('original air date'))
  except:
    release = 'NaN'


  try:
    genres = data.get('genres')
  except:
    genres = 'NaN'


  cast = []
  for i in range(3):
    try:
      fxn = data.get('cast')[i]
      cast.append(fxn['name'])
    except:
      pass


  crew = []
  posts = ['directors', 'producers', 'writers', 'composers', 'cinematographers', 'editors', 'casting directors']
  for i in posts:
    try:
      temp = data.get(i)[0]['name']
      if temp not in crew:
        crew.append(temp)
    except:
      pass


  try:
    ratings = data.get('rating')
  except:
    ratings = 'NaN'
  
  
  try:
    votes = data.get('votes')
  except:
    votes = 'NaN'
  
  
  try:
    plot = data.get('plot')[0]
  except:
    plot = 'NaN'

  return release, genres, cast, crew, ratings, votes, plot
Release = []
Genres = []
Cast = []
Crew = []
Ratings = []
Votes = []
Plot = []
temp = 0

for id in imdb_id:
  release, genres, cast, crew, ratings, votes, plot = create_db(id)
  Release.append(release)
  Genres.append(genres)
  Cast.append(cast)
  Crew.append(crew)
  Ratings.append(ratings)
  Votes.append(votes)
  Plot.append(plot)
  temp = temp + 1
  if temp%50==0:
    print('Done with {} movies'.format(temp))
new_db['Release'] = Release
new_db['Genres'] = Genres
new_db['Cast'] = Cast
new_db['Crew'] = Crew
new_db['Ratings'] = Ratings
new_db['Votes'] = Votes
new_db['Plot'] = Plot
new_db.count()
new_db.head()
new_db.to_csv('Outputs/movies_database.csv', index=False)<jupyter_output><empty_output><jupyter_text>Task 3: Additional data processing<jupyter_code>df = pd.read_csv('Outputs/movies_database.csv')
# Divided by 35000 because highest voted indian movie has 350,000 votes
df['Popularity'] = (df['Votes']/35000+df['Ratings'])/2
df.head()
from datetime import date 
todays_date = date.today()
present_year = todays_date.year
RY = df['Release'].tolist()
release_year = []
for i in RY:
  release_year.append(i[7:11])
year = release_year[0]

AOC = []
for year in release_year:
  try:
    AOC.append(str(int(present_year)-int(year))+" years")
  except:
    AOC.append('NaN')
df['Age of Content'] = AOC
df.head()
df.to_csv('Outputs/movies_database_aditional_data.csv', index=False)<jupyter_output><empty_output><jupyter_text>Task 4: Exploratory data analysis<jupyter_code>db = pd.read_csv('Outputs/movies_database.csv')
Genres = db['Genres'].tolist()
Actors = db['Cast'].tolist()
db['Cast'][0]
movie_genras = []
movie_cast = []

for i in Actors:
  try:
    ii = i.strip('][').split(', ')
    for actor in ii:
      movie_cast.append(actor)
  except:
    movie_cast.append('NaN')

for j in Genres:
  try:
    jj = j.strip('][').split(', ')
    for genre in jj:
      movie_genras.append(genre)
  except:
    movie_genras.append('NaN')

df = pd.DataFrame(list(zip(movie_cast, movie_genras)), columns =['Actor', 'Genre'])
df['Genre'] = df[df.G != 'Url not found!!']
df.head()
df['Genre'].value_counts()
import matplotlib.pyplot as plt
df['Genre'].value_counts().plot(kind= 'bar')
plt.xlabel("Genre")
plt.ylabel("No. of movies")
plt.savefig('Plots/Top_Genres.png')
plt.show()
df['Actors'].value_counts()[:10]
df['Actors'].value_counts()[:10].plot(kind= 'bar')
plt.xlabel("Actor")
plt.ylabel("No. of movies")
plt.savefig('Plots/Top10_Actors.png')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1503570739239529, 'fraction_numerical': 0.013317892298784018, 'mean_word_length': 3.829450139794967, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '122000', 'license': 'MIT', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1907, 'n_words': 459, 'path': 'imdb_data.ipynb', 'repo_name': 'Mukulthakur17/IMDB-Data-Analysis', 'size': '5181'}