小编Sca*_*Sca的帖子

在python中计算一行中1的数量

我有一个列名从 P1 到 P10 的数据框

  p1 p2 p3  p4  p5 
    0   0  0  1    1
    0   0  0  0    0
    1   1  1  1    1

the total number of 1 has to be displayed at the end of the row 
example : first row = 2 
second row = 0
third row = 5
Run Code Online (Sandbox Code Playgroud)

python count pandas

4
推荐指数
1
解决办法
600
查看次数

使用 Python 将维基百科数据提取到 txt 文件

我已经实现了以下代码来从维基百科页面提取数据

import bs4
import sys
import requests

res = requests.get('https://en.wikipedia.org/wiki/Agriculture' )
res.raise_for_status()
wiki = bs4.BeautifulSoup(res.text,"html.parser")
for i in wiki.select('p'):
    print(i.getText())
Run Code Online (Sandbox Code Playgroud)

该代码根据我的需要从页面中提取所有数据。但是我想使用 Python 将其存储在文本文件中,但我无法做到。该文本文件的名称应为“Agriculture”(如果从 URL 本身中提取该名称则更好,以便可以在多个 wiki 页面上使用)。

python io file list web-scraping

1
推荐指数
1
解决办法
1967
查看次数

标签 统计

python ×2

count ×1

file ×1

io ×1

list ×1

pandas ×1

web-scraping ×1