这是我的代码的样子
pos_list = []
for i in range(len(df)):
if df.loc[i, "sentiment"] == 1:
pos_list = df.loc[i, "tweets"].tolist()
else:
pass
print(pos_list)
所以如果情绪== 1,我想在tweets列中添加一行到列表中
答案 0 :(得分:1)
尝试使用append
方法:
pos_list = []
for i in range(len(df)):
if df.loc[i, "sentiment"] == 1:
pos_list.append(df.loc[i, "tweets"])
else:
pass
print(pos_list)
希望这会有所帮助。