0

im trying to check if a row in my csv file has a usage that says "Training", "PublicTest", or "PrivateTest" (Each row is classified as one of these three, except even though usage is the word "Training", the program recognizes it as not the same word, anything I can do to fix this?


training_data = []
test_data = []

train_images = []
train_labels = []

test_images = []
test_labels = []

def format_data(path):
    for row in open(path):
        idx = 0
        with open(path) as d:
            emotion, image, usage = d.readlines()[idx + 1].split(",")

            if usage is "Training":
                train_labels.append(int(emotion))
                imageArr = []
                imageArr.append(image)
                train_images.append(imageArr)
                print(train_images)

            elif usage is "PublicTest" or usage is "PrivateTest":
                test_labels.append(int(emotion))
                imageArr = []
                imageArr.append(image)
                test_images.append(imageArr)
                print(test_images)

            idx += 1

    
        print("This row has been iterated over!")
        # print(row)
        

    # add any more formatting

    # train_images/255.0
    # test_images/255.0


def load_data():
    return train_images, train_labels, test_images, test_labels


format_data(path)```

1 Answers1

0

Please, always use == when testing for equality. So in your case try using usage == "Training" instead of usage is "Training".

Here is more on the topic: Is there a difference between "==" and "is"?.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ivan T.
  • 31
  • 3