我已經將數據插入到熊貓數據框中。像圖片建議 ,你可以看到有一些行包含url鏈接,我想刪除所有的url鏈接,並用「」替換它們(沒有東西只是擦除它),你可以看到第4行有一個URL有其他也有網址的行。我想通過status_message列中的所有行查找任何網址並將其刪除。我一直在尋找這How to remove any URL within a string in Python,但我不知道如何在數據幀上使用它。所以第4行現在應該喜歡投票。從python熊貓數據框中的大量文本中逐行刪除一個URL
0
A
回答
0
我認爲你可以做一些簡單的
for index,row in data.iterrows():
desc = row['status_message'].lower().split()
print ' '.join(word for word in desc if not word.startswith(('www.','http')))
只要網址開頭爲「WWW」。
0
您可以使用.replace()
用正則表達式來做到這一點,即
df = pd.DataFrame({'A':['Nice to meet you www.xy.com amazing','Wow https://www.goal.com','Amazing http://Goooooo.com']})
df['A'] = df['A'].replace(r'http\S+', '', regex=True).replace(r'www\S+', '', regex=True)
輸出:
A 0 Nice to meet you amazing 1 Wow 2 Amazing
4
您可以使用str.replace
與case=False
參數:
df = pd.DataFrame({'status_message':['a s sd Www.labour.com',
'httP://lab.net dud ff a',
'a ss HTTPS://dd.com ur o']})
print (df)
status_message
0 a s sd Www.labour.com
1 httP://lab.net dud ff a
2 a ss HTTPS://dd.com ur o
df['status_message'] = df['status_message'].str.replace('http\S+|www.\S+', '', case=False)
print (df)
status_message
0 a s sd
1 dud ff a
2 a ss ur o
相關問題
- 1. Python熊貓數據框從列表中刪除行按價值
- 2. 從熊貓數據框中刪除部分無效數據(Python)
- 3. 大熊貓多指標數據框中刪除行
- 4. 刪除已知從大熊貓異常數據框中
- 5. 熊貓:如何根據列表從數據框中刪除行?
- 6. 熊貓:從數據框中刪除相反的副本
- 7. 從熊貓數據框中刪除具有空值的行
- 8. Python 2.7替換熊貓數據框中的一個熊貓DF
- 9. 遍歷數據幀逐一(大熊貓)
- 10. 在大熊貓數據框中刪除行數據佔總數的百分比
- 11. 從熊貓數據框中刪除閏年一天
- 12. 使用熊貓中的列表刪除數據框中的行
- 13. 刪除數據框中列條件的大熊貓
- 14. 在Python中分割大熊貓熊貓數據框
- 15. 如何從熊貓數據框中的列表中刪除值?
- 16. Python的大熊貓:刪除行不是從數據幀匹配多個條件
- 17. 刪除與從大熊貓
- 18. Python:從熊貓數據框爆炸行
- 19. 從python變量載入數據到熊貓數據框中
- 20. 在熊貓數據框的列中刪除包含'False'的行
- 21. 從熊貓數據框中
- 22. 從熊貓數據框中
- 23. 如何刪除熊貓數據框中特定日期的行?
- 24. 從熊貓數據框的字符串列中刪除b''
- 25. 錯誤上從大熊貓數據幀中移除串 - 的Python
- 26. 從熊貓數據框中刪除重複,如果重複值是下一行
- 27. 字典從大熊貓數據幀列中刪除
- 28. 在Python中刪除具有字符串值的熊貓數據框的行3.4.1
- 29. 熊貓數據框 - 刪除異常值
- 30. 大熊貓數據框中:的的.index
某些URL以http: ... –
請upvote,如果它回答你的問題 – Gayatri