Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Data Science Basics Cleaning Data Clean Up Your Data

Andrew Merrick
Andrew Merrick
20,151 Points

Clean Up Your Data - Length is 0, not 56

I keep on getting Length 0 instead of 56 and my code, to my eyes, is exactly as the instructor's. Can anyone review and see where I'm getting stuck?

I've noticed that if I add an else clause where I print the matches_search_term I get 56 empty lists...

from s2v5 import *

def create_bool_field_from_search_term(data_sample, search_term):
    new_array = []
    new_array.append(data_sample[0].append(search_term))

    for row in data_sample[1:]:
        new_bool_field = False
        if search_term in row[7]:
            new_search_term = True

        row.append(new_bool_field)
        new_array.append(row)

    return new_array

def filter_col_by_bool(data_sample, col):
    matches_search_term = []

    for item in data_sample[1:]:
        if item[col]:
            matches_search_term.append(item)
               # else:
                        # print(matches_search_term)

    return matches_search_term

my_new_csv = create_bool_field_from_search_term(data_from_csv, "cashmere")
number_of_cashmere_ties = number_of_records(filter_col_by_bool(my_new_csv, 11))
print("Length: ", number_of_cashmere_ties)

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Andrew.

I can't remember this code in particular but I have a question:

I think it is line 10, what is this?

new_search_term = True

It looks like you want new_bool_field there instead of what you actually have in order to be able to count from the array then, right?

Let me know if this helps.

Thanks, Vittorio

Andrew Merrick
Andrew Merrick
20,151 Points

Vittorio: starting at 2:31 in the video, the instructor says that we want it to be true because "it exists".

Andrew Merrick
Andrew Merrick
20,151 Points

Vittorio: I completely misread what you typed and you are 100% correct. Thanks for your help!