Python Data Science Basics Cleaning Data Filtering Rows

J R
PRO
J R
Pro Student 11,462 Points

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?

KRIS NIKOLAISEN
KRIS NIKOLAISEN
Pro Student 44,827 Points

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

J R
J R
Pro Student 11,462 Points
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.

J R
J R
Pro Student 11,462 Points

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.