![](/img/trans.png)
[英]How to print the slice of the list of words that only includes letters. python? But what am i missing?
[英]Pandas is not recognizing words, but only letters. How can I do so when I slice, it gives me the words not the letters?
當我將此功能應用於我的文本時,它會被清除,但是當我在單元格中搜索特定單詞時,它只給我字母,而不是單詞。
def clean_text(x):
txt = re.sub(r'https?://\S+', '', x)
txt = re.sub('[^A-Za-z]+', ' ', x)
txt = ' '.join(txt.split())
return txt
當我嘗試以下列方式獲取第一個單詞(應該是“未來”)時:df_clean.iloc[0,][0],我只得到一個“F”。
如何通過單元格中的索引找到單詞?
df_clean.iloc[0,][0]
將返回df_clean.iloc[0,]
的第 0 個元素,鑒於df_clean.iloc[0,]
是一個字符串,它將是第一個字母。 你不想要第 0 個元素,你想要第 0 個詞。 如果單元格有一個列表,那么你正在做的事情就會起作用。
兩種解決方案:
clean_text()
) txt.split()
這樣你就有了列表df_clean.iloc[0,][0:str.index(' ')]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.