Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从movie review数据集生成用于分类的数据帧?_Python_Pandas_Dataframe_Svm_Sentiment Analysis - Fatal编程技术网

Python 如何从movie review数据集生成用于分类的数据帧?

Python 如何从movie review数据集生成用于分类的数据帧?,python,pandas,dataframe,svm,sentiment-analysis,Python,Pandas,Dataframe,Svm,Sentiment Analysis,我是新来的熊猫,试图用一些数据来练习。我得到以下格式的培训数据集。 这是电影评论的数据集。如何从这类数据中生成数据帧以用于SVM分类。我已经使用[12000*12]大小数据进行分类,其中每行的属性数相等。但在这里,属性的长度并不相等。我如何修改这个 PhraseId SentenceId Phrase Sentiment 1 1 Wanker Goths are on the loose ! 2 2 1 Wanker Goths 2 3 1 Wanker

我是新来的熊猫,试图用一些数据来练习。我得到以下格式的培训数据集。
这是电影评论的数据集。如何从这类数据中生成数据帧以用于SVM分类。我已经使用[12000*12]大小数据进行分类,其中每行的属性数相等。但在这里,属性的长度并不相等。我如何修改这个

PhraseId    SentenceId  Phrase  Sentiment
1   1   Wanker Goths are on the loose ! 2
2   1   Wanker Goths    2
3   1   Wanker  2
4   1   Goths   2
5   1   are on the loose !  2
6   1   are on the loose    2
7   1   on the loose    2
8   1   the loose   2
9   2   made Eddie Murphy a movie star and the man has n't aged a day . 3
10  2   made Eddie Murphy a movie star and the man  3
11  2   Eddie Murphy a movie star and the man   2
12  2   a movie star and the man    2
13  2   a movie star and    2
14  2   has n't aged a day .    2
15  2   has n't aged a day  3
16  2   aged a day  2
这是实际培训(部分)

我的目标是使用数字数据映射从该数据集形成一个数据帧,以便我可以使用该数据帧对情绪进行分类。

使用纯python:

t = """PhraseId    SentenceId  Phrase  Sentiment
1   1   Wanker Goths are on the loose ! 2
2   1   Wanker Goths    2
3   1   Wanker  2
4   1   Goths   2
5   1   are on the loose !  2"""
按换行符拆分字符串:

t = t.split('\n')
然后获取拆分字符串的列表:

s = [i.split() for i in t]
然后合并短语并获得数据帧:

import pandas as pd
df = pd.DataFrame([(i[0],i[1],' '.join(i[2:-1]),i[-1]) for i in s],columns=s[0])
df = df.ix[1:]
print df

我知道熊猫有一个get_dummies(),但我从来没有在文本分类问题中使用过。对不起,我只知道如何将其转换为数据帧。谢谢,先生。我知道这部分。我实际上需要进一步转换