当我尝试使用其他索引列表从pandas系列和/或样本列表中选择项目时,输出为['and','and','and','and','and', '和']
我试图将pandaSeries转换为np.array,但没有改变! 没有使用tolist函数!
data_list = sample_memo.strip().split()
data_pandas = pd.Series(data_list)
def function1(word):
word_occurance = np.array(data_pandas[data_pandas == word].index)
next_indexis = (word_occurance+1).tolist()
next_words = data_pandas[next_indexis].tolist()
print(next_words)
输入
word : 'ahead' \n
data_pandas : \n
0 Milt,
1 we're
2 gonna
3 need
4 to
5 go
6 ahead
7 and
8 move
9 you
10 downstairs
11 into
12 storage
13 B.
14 We
15 have
16 some
17 new
18 people
19 coming
20 in,
21 and
22 we
23 need
输出
['and', 'and', 'and', 'and', 'and', 'and']