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 Filtering Rows

My output includes "Length: 56" when I follow along in this video.

When I run s3v2.py, my output is -

Length: 56
Found 3382 silk ties

Where Kat's output at around 4 minutes does not include the length.

Anybody know why this is?

Can you post your code? I tried downloading the project files but couldn't find s3v2.py.

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_bool_field = 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)

  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)
from s3v1 import *

def filter_col_by_string(data_sample, field, filter_condition):
  filtered_rows = []

  col = int(data_sample[0].index(field))
  filtered_rows.append(data_sample[0])

  for item in data_sample[1:]:
    if item[col] == filter_condition:
      filtered_rows.append(item)

  return filtered_rows

silk_ties = filter_col_by_string(data_from_csv, "material", "_silk")
print("Found {} silk ties".format(number_of_records(silk_ties)))

The first is s3v1, and the second is s3v2. Included both because I think the issue lies within the first script but I am not sure.

The line : print("Length:", number_of_cashmere_ties) in s3v1 seems to be the problem.

Did she simply comment this line out between the videos? Or am I missing something else?

Admittedly this is not a big deal. I just wanted to know.