Python 如何迭代列(类型:series)
我想迭代一列的行(type:series),每一行代表一系列单词,我想对每个单词进行分类 某些行的示例:Python 如何迭代列(类型:series),python,pandas,Python,Pandas,我想迭代一列的行(type:series),每一行代表一系列单词,我想对每个单词进行分类 某些行的示例: ['hard', 'house', 'warm', 'lovely'] ['beauty', morning', 'work', 'sick'] 我有以下代码: for i, row in df['splitsent'].items(): test=i['splitsent'] 我得到这个错误: ' test_set=i['stoplist'] TypeError:
['hard', 'house', 'warm', 'lovely']
['beauty', morning', 'work', 'sick']
我有以下代码:
for i, row in df['splitsent'].items():
test=i['splitsent']
我得到这个错误:
' test_set=i['stoplist']
TypeError: 'int' object is not subscriptable '
行是数据。i是整数索引:0,1,2。。。所以
i['splitsent']
对于整数没有意义,即。这是
ItErrors
for x , y in df.iterrows():
print(x)#index
print(y)#serise row
如果这是一个系列
for x,y in zip(df.index,df.Value):#df.Value.iterrows()
print(x)#index
print(y)#value
你能添加所需的输出吗?所需的输出是:{'hard':'neg','house':'neu','warm':'pos','lovely':'pos'}{'beauty':'pos',morning':'neu','neu','sick':'neg'}我定义了积极和消极的特征,训练集和一个返回字典的函数,它可以工作。但在这个级别的代码中,我想将每一行(系列)定义为一个测试集
series
hasiteritems
,对于索引值,我想做的是将每一行进行排序:row1['splitsent',row2['splitsent',],所以这就是为什么我把i['splitsent']