Python - 格式化二进制分类器的csv数据

时间:2017-09-11 05:17:21

标签: python csv classification

我有一些headers = [artist_list, song_list, lyrics_track, lyrics_artist, lyrics]`, 数据格式如下:

with open('lyrics.tsv', "rU") as f:
    reader = csv.reader(f, delimiter="\t")
    for i, line in enumerate(reader):
        print 'line[{}] = {}'.format(i, line)

和此代码段:

(...)

line[808] = ['Pearl Jam', 'Wishlist', 'Wishlist', 'Pearl Jam', "I wish I was a neutron bomb\nfor once I could go off\nI wish I was a sacrifice\nbut somehow still lived on\nI wish I was a sentimental\nornament you hung on\nthe Christmas tree, I wish I was\nthe star that went on top\nI wish I was the evidence\nI wish I was the grounds\nfor fifty million hands upraised and opened toward the sky\nI wish I was a sailor with\nsomeone who waited for me\nI wish I was as fortunate\nas fortunate as me\nI wish I was a messenger\nand all the news was good\nI wish I was the full moon shining\noff a Camaro's hood\nI wish I was an alien\nat home behind the sun\nI wish I was the souvenir\nyou kept your house key on\nI wish I was the pedal break\nthat you depended on\nI wish I was the verb to trust\nand never let you down\nI wish I was a radio song\nthe one that you turned up\nI wish ..."]

打印:

lyrics

现在我想使用数据进行分类,只保留所有行的0并为二进制值添加一列(始终相同, lyrics type (...) (...) I wish I was a neutron bomb\nfor once I could go off.. 0 ),因此数据转换为:

fillColor

我怎么能从上面的代码开始呢?

1 个答案:

答案 0 :(得分:0)

我认为这样的事情可能有效(假设您的数据位于名为lyrics_df的数据框中):

lyrics_df['type']=0