<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Filter a CSV
We're going to use built-in Python modules - programs really - to download a csv file from the Internet and save it locally.
CSV stands for comma-separated values. It's a common file format a file format that resembles a spreadsheet or database table in a text file.
So first, let's import two built-in Python modules
Step1:  We're going to download a csv file. What should we name it?
Step2:  Now we need a URL to a CSV file out on the Internet.
For this project we're going to download a CSV file that the FDIC compiles of all the banks that have failed since October 1, 2000.
The file we want is at https
Step3:  The output shows we successfully downloaded the file and saved it
Let's open a new file so we can filter just the data we want. We add the newline parameter when we open the file to write so it doesn't add additional, blank rows on Windows machines.
Step4:  We will use the writer method to write data to a file by passing in the name of the new file as the first argument and delimiter as the the second.
Then we will go ahead and use python's csv reader to open the file and see what is inside.
We specify the name of the file we just created, and we add a setting so we can open and read almost any CSV file.
<ASSISTANT_TASK:>
Python Code:
from urllib.request import urlretrieve
import csv
Explanation: Filter a CSV
We're going to use built-in Python modules - programs really - to download a csv file from the Internet and save it locally.
CSV stands for comma-separated values. It's a common file format a file format that resembles a spreadsheet or database table in a text file.
So first, let's import two built-in Python modules: urllib and csv. 
urllib is a module that allows Python to make http requests to URLs on the web to fetch HTML. It contains a submodule called request. And inside there we want a specific method called urlretrieve
csv is a module that helps Python work with tabular data extracted from spreadsheets and databases
End of explanation
downloaded_file = "banklist.csv"
Explanation: We're going to download a csv file. What should we name it?
End of explanation
urlretrieve("https://s3.amazonaws.com/datanicar/banklist.csv", downloaded_file)
Explanation: Now we need a URL to a CSV file out on the Internet.
For this project we're going to download a CSV file that the FDIC compiles of all the banks that have failed since October 1, 2000.
The file we want is at https://s3.amazonaws.com/datanicar/banklist.csv.
If the internet is uncooperative, we can also use the local version of the file in the project1/data/ directory, and structure out code a little differently.
To do this, we use that program within the urllib module to download the file and save it to our project folder. It's called urlretrieve and for our purposes starting out think of it as a way to download a file from the Internet.
urlretrieve takes two arguments to download a file. First specify our target URL, and then we give it a name for the file we want to create.
End of explanation
filtered_file = open('california_banks.csv', 'w', newline='')
Explanation: The output shows we successfully downloaded the file and saved it
Let's open a new file so we can filter just the data we want. We add the newline parameter when we open the file to write so it doesn't add additional, blank rows on Windows machines.
End of explanation
# create our output
output = csv.writer(filtered_file, delimiter=',')
# open our downloaded file
with open(downloaded_file, 'r') as file:
    
    # use python's csv reader to access the contents
    # and create an object that represents the data
    csv_data = csv.reader(file)
    
    # write our header row to the output csv
    header_row = next(csv_data)
    print(header_row)    
    output.writerow(header_row)
    
    # loop through each row of the csv
    for row in csv_data:
        # now we're going to use an IF statement
        # to find items where the state field
        # is equal to California
        if row[2] == 'CA':
            
            # write the row to the new csv file
            output.writerow(row)          
        
            # and print the row to the terminal
            print(row)
            # print the data type to the terminal
            print(type(row))
            # print the length of the row to the terminal
            print(len(row))            
            
        # otherwise continue on
        else:
            continue
            
# close the output file
filtered_file.close()
Explanation: We will use the writer method to write data to a file by passing in the name of the new file as the first argument and delimiter as the the second.
Then we will go ahead and use python's csv reader to open the file and see what is inside.
We specify the name of the file we just created, and we add a setting so we can open and read almost any CSV file.
End of explanation
<END_TASK>