我已經將數據插入到熊貓數據框中。像圖片建議 ,你可以看到有一些行包含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. 刪除熊貓數據框中的行
- 2. Python熊貓數據框從列表中刪除行按價值
- 3. 從熊貓數據框中刪除部分無效數據(Python)
- 4. 大熊貓根據病情刪除數據框中行
- 5. 刪除數據框中行大熊貓在表
- 6. 大熊貓多指標數據框中刪除行
- 7. 刪除已知從大熊貓異常數據框中
- 8. 熊貓:如何根據列表從數據框中刪除行?
- 9. 熊貓:從數據框中刪除相反的副本
- 10. Python 2.7替換熊貓數據框中的一個熊貓DF
- 11. 從熊貓數據框中刪除具有空值的行
- 12. 在刪除Python中的行時縮小熊貓數據框中的行數
- 13. 刪除熊貓數據框中每一行的標點符號
- 14. 遍歷數據幀逐一(大熊貓)
- 15. 從熊貓數據框中刪除特定行
- 16. 在大熊貓數據框中刪除行數據佔總數的百分比
- 17. 從熊貓數據框中刪除閏年一天
- 18. 使用熊貓中的列表刪除數據框中的行
- 19. 在Python中分割大熊貓熊貓數據框
- 20. 刪除數據框中列條件的大熊貓
- 21. 如何從熊貓數據框中的列表中刪除值?
- 22. Python的大熊貓:刪除行不是從數據幀匹配多個條件
- 23. 刪除與從大熊貓
- 24. Python:從熊貓數據框爆炸行
- 25. 從python變量載入數據到熊貓數據框中
- 26. 從熊貓數據框中
- 27. 從熊貓數據框中
- 28. 從熊貓數據框中
- 29. 從熊貓數據框中
- 30. 在熊貓數據框的列中刪除包含'False'的行
某些URL以http: ... –
請upvote,如果它回答你的問題 – Gayatri