In Cleaning and Preparing Data in Python Practice Problems: question 5, I have the code below. But it complains “File listings_clean.csv does not have the expected content.” From print out, I don’t see anything different from the answer.
Screen Link:
My Code:
import csv
def write_csv(rows):
f = open('listings_clean.csv', mode='w')
writer = csv.writer(f)
for row in rows:
writer.writerow(row)
f.close()
# Write your code below
def clean_available_col():
f = open('listings.csv',mode='r')
reader=csv.reader(f)
rows=list(reader)[1:]
dic={'Y':'yes','y':'yes','NO':'no','n':'no'}
for row in rows:
if row[3] in dic:
row[3]=dic[row[3]]
print(row)
write_csv(rows)
clean_available_col()
f=open('listings_clean.csv',mode='r')
reader=csv.reader(f)
rows = list(reader)
for i in range(8):
print(rows[i])
What I expected to happen:
What actually happened:
Replace this line with the output/error