<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Goal 1
Injest file as pure text
Step1:  Import data as a list of lines
Step2:  Import data as a data frame
Step3:  Goal 2
Step4:  Goal 3
<ASSISTANT_TASK:>
Python Code:
MovieTextFile = open("tmdb_5000_movies.csv")
# for line in MovieTextFile:
#    print(line) # not quite right
# type(MovieTextFile)
Explanation: Goal 1
Injest file as pure text
End of explanation
import csv
with open("tmdb_5000_movies.csv",encoding="utf8") as f:
    reader = csv.reader(f)
    MovieList = list(reader)
MovieList[:5]
Explanation: Import data as a list of lines
End of explanation
import pandas as pd
movies = pd.read_csv("tmdb_5000_movies.csv")
movieFrame = pd.DataFrame(movies)
movieFrame[:5]
Explanation: Import data as a data frame
End of explanation
#pull out genres array of JSON strings from data frame
genres = movieFrame['genres']
# genresFrame = pd.DataFrame(genres)
genres[:5]
# Pull out list of names for each row of the data frame
# Start with testing first row and iterating through JSON string
import json
genreList = []
genre = json.loads(genres[0])
for i,val in enumerate(genre):
    genreList.append(genre[i]['name'])
genreList
# Iterate through indices of genre array to create a list of lists of genre names
import json
genresAll = []
for k,x in enumerate(genres):
    genreList = []
    genre = json.loads(genres[k])
    for i,val in enumerate(genre):
        genreList.append(genre[i]['name'])
    genresAll.append(genreList)
genresAll[:10]
genreSeries['W'] = pd.Series(genresAll,index=movieFrame.index)
genreFrame = pd.DataFrame(genreSeries['W'],columns=['GenreList'])
genreFrame[:5]
genreDummies = genreFrame.GenreList.astype(str).str.strip('[]').str.get_dummies(', ')
genreDummies[:10]
# append lists as a column at end of dataframe
movieGenreFrame = pd.merge(movieFrame,genreFrame,how='inner',left_index=True, right_index=True)
movieGenreFrame[:5]
wideMovieFrame = pd.merge(movieGenreFrame,genreDummies,how='inner',left_index=True,right_index=True)
wideMovieFrame[:5]
Explanation: Goal 2
End of explanation
longMovieFrame = pd.melt(wideMovieFrame, id_vars=movieGenreFrame.columns, value_vars=genreDummies.columns, 
                         var_name='Genre',value_name="genre_present")
longMovieFrame[:10]
# test results with 'Avatar' example
longMovieFrame[longMovieFrame['title']=='Avatar']
# If only retaining "true" genres
longMovieFrameTrimmed = longMovieFrame[longMovieFrame['genre_present']==1]
longMovieFrameTrimmed[:5]
Explanation: Goal 3
End of explanation
<END_TASK>