Cleaning and preparing data in python practice problem

Screen Link:

My Code:

def write_csv(rows):
    f = open('listings_clean.csv', mode='w')
    writer = csv.writer(f)
    for row in rows:
# Write your code below
def clean_available_col():
    #Read the CSV file
    from csv import reader
    f = open('listings.csv')
    reader = reader(f)
    rows = list(reader)
    #clean last column
    for row in rows:
        if row[-1] == 'y' or row[-1] == 'Y':
            row[-1] = 'yes'
        if row[-1] == 'n' or row[-1] == 'NO':
            row[-1] = 'no'
    #write the cleaned file 
#call the funtion and check results
f = open('listings_clean.csv')
reader = csv.reader(f)
rows = list(reader)
for i in range(8):

What I expected to happen:

What actually happened:

Replace this line with the output/error

I don’t understand what this line actually does ‘writer.writerow(row)’ in the above code

1 Like

Hi @harsharam911: You can find the explanation to this simply by googling it as seen in this article.

The writerows() method essentially does this:

def writerows(self, rows):
    for row in rows:

where each row must be a sequence of columns. A string is a sequence of individual characters, so that’s what you get written: individual characters separated by your chosen delimiter.

Hope this helps!

1 Like