Question: I have done splitting on the csv file(link given below) and my data output is given below. I need little help in comparing **country** column and return only the movie names that are made in the USA only. How do I do that?

```
data = open("movie_metadata.csv", "r").read().split("\\n")
movie_data = [i.split(",") for i in data]
print(movie_data[1:4])

output:
[['movie_title','director_name','color','duration','actor_1_name','language',
  'country','title_year'],
['Avatar','James Cameron','Color','178','CCH Pounder','English','USA',
 '2009'],
["Pirates of the Caribbean: At World's End",'Gore Verbinski','Color',
 '169','Johnny Depp','English','USA','2007'],
['Spectre','Sam Mendes','Color','148','Christoph Waltz','English','UK',
 '2015']]

```

[CSV File](http://www.sharecsv.com/s/dcb38ee98d6116ea5e9b3cdea3572115/Movie_metadata.csv)

Answer: 
You want to filter the list based on the country column. 

```
us_movies = [movie for movie in movies if movie[6] == 'USA'] 

```

You can also transform the line into just the title if you like.

```
us_movie_titles = [movie[0] for movie in movies if movie[6] == 'USA']

```

If you want a corresponding list of match predicate results, this will work:

```
is_match = [movie[6] == 'USA' for movie in movies]

```

Note, the size of the first two lists may be smaller than the original list, but is\_match will have the same size and ordering as your original list.

To add the booleans to your full dataset:

```
movies_with_usa = [m[0] + [m[1]] for m in zip(movies, is_match)]

```

But what you really have is named data, so it's probably more appropriate in a dictionary or object. Also, if you're reading a csv file, a csv reader is part of the standard library. So for something a little more robust

```
import csv

def read_data(filename):
    with open(filename) as f:
        reader = csv.DictReader(f)
        return [row for row in reader]     

def match(record, field, value):
    return record[field] == value

data = read_data("movie_metadata.csv")
us_movies = [record for record in data if match(record, 'country', 'USA')]      

```
You want to use a `pandas` dataframe and then you can filter very easily based on the columns.

```
import pandas as pd
df = pd.DataFrame(movie_data[1:],columns = movie_data[0])
                                movie_title   director_name  color duration     actor_1_name language country title_year
0                                    Avatar   James Cameron  Color      178      CCH Pounder  English     USA       2009
1  Pirates of the Caribbean: At World\'s End  Gore Verbinski  Color      169      Johnny Depp  English     USA       2007
2                                   Spectre      Sam Mendes  Color      148  Christoph Waltz  English      UK       2015

df[df.country == "USA"]
                                movie_title   director_name  color duration actor_1_name language country title_year
0                                    Avatar   James Cameron  Color      178  CCH Pounder  English     USA       2009
1  Pirates of the Caribbean: At World\'s End  Gore Verbinski  Color      169  Johnny Depp  English     USA       2007

```