[英]loop through a dataframe and append rows from a specific column to a new list when the condition is met
這是我的代碼的樣子
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,我想將推文列中的一行添加到列表中
嘗試使用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)
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.