0

when I import this dataset:

dataset = pd.read_csv('lyrics.csv', delimiter = '\t', quoting = 2)

it prints like so:

                                 lyrics,classification
0    I should have known better with a girl like yo...
1    You can shake an apple off an apple tree\nShak...
2    It's been a hard day's night\nAnd I've been wo...
3    Michelle, ma belle\nThese are words that go to...
4    Can't buy me love, love\nCan't buy me love\nI'...
5    I love you\nCause you tell me things I want to...
6    I dig a Pygmy by Charles Hawtrey and the Deaf ...
7    The song a robin sings,\nThrough years of endl...
8    Love me tender, love me sweet,\nNever let me g...
9    Well, it's one for the money,\nTwo for the sho...
10   All the words that I let her know\nStill could...

and if I print (dataset.columns), I get:

Index([u'lyrics,classification'], dtype='object')

but if I try to prints the lyrics, like so:

for i in range(0, len(dataset)):
    lyrics=dataset['lyrics'][i]
    print lyrics

I get the following error:

KeyError: 'lyrics'

what am I missing here?

2
  • change the delimiter from '\t' to ',' Commented Sep 11, 2017 at 19:55
  • What's missing is you need to figure out what your actual delimiter is. Commented Sep 11, 2017 at 20:03

1 Answer 1

1

Since you set the delimiter to be a tab (\t), the header isn't be parsed as you think. 'lyrics,classification' is one column name. If you want to keep the delimiter as a tab, then between lyrics and classification there should be a tab rather than a comma.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.