Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中整理HTML表(正确计算行数)_Html_Python 3.x_Pandas_Beautifulsoup_Html Parsing - Fatal编程技术网

在Python中整理HTML表(正确计算行数)

在Python中整理HTML表(正确计算行数),html,python-3.x,pandas,beautifulsoup,html-parsing,Html,Python 3.x,Pandas,Beautifulsoup,Html Parsing,我有一个 我希望能够按值计算列中的条目数:更改、状态、请求类型。例如,新对象出现两次 更改列具有以下值:新建对象、删除对象、更改“对象文本”属性、更改“对象标题”属性 状态列中有值:处于审核中(或备选组合值) 需求类型列具有以下值:功能需求、信息、Überschrift(或替代组合值) 尝试过的解决方案(repl.it有一个很好的在线IDE): 相应的输出: 2 1 1 0 3 1 0 3 Not found! Not found! Not found! Not found! Not found

我有一个

我希望能够按值计算列中的条目数:更改状态请求类型。例如,新对象出现两次

更改列具有以下值:新建对象、删除对象、更改“对象文本”属性、更改“对象标题”属性

状态列中有值:处于审核中(或备选组合值)

需求类型列具有以下值:功能需求、信息、Überschrift(或替代组合值)

尝试过的解决方案(repl.it有一个很好的在线IDE):

相应的输出:

2
1
1
0
3
1
0
3
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Found!
Not found!
Not found!
Found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
Not found!
我尝试的解决方案不是动态的,也不匹配列,而是使用find_all进行搜索,以匹配表达式并对其进行计数,这不是最优的

a) 如何使其动态化,以便只考虑所提到的列,并获得这三列的每个值类别的计数器?在给定的示例中,“Info.”值被错误地找到了三次,尽管只需要找到两次,这是正确的答案。这需要对三列的每个值都执行

b) 如何输出过滤器的计数器: 新的对象和功能需求。(=0), 新对象和信息。(=1), 对象已删除&功能请求。(=1)? 尝试了来自的不同功能,但无法使其工作


c) 可选问题:状态请求类型列可以有不同的值,具体取决于表的定义。这意味着这些值可以更改,而不是固定的。我们是否可以计算这些值(通过过滤数组或列表中的唯一值),然后计算受影响列中包含的每个唯一值的数量。

我不确定我是否理解您的第二个和第三个问题(并且,根据政策要求,您应该分别发布每个问题),但下面是如何处理第一个问题,它还可以帮助你完成剩下的事情

import pandas as pd
ht = """[your html]"""
targets = ['Change', 'Status', 'Req._Type']
df = pd.read_html(ht)[1]

for target in targets:
    print(df[target].value_counts())
    print('---')
输出:

NEW OBJECT                         2
Attribute "Object Text" Changed    1
OBJECT DELETED                     1
Name: Change, dtype: int64
---
In Review    3
Name: Status, dtype: int64
---
Info.              2
functional Req.    1
Name: Req._Type, dtype: int64

我不确定我是否理解您的第二个和第三个问题(根据政策要求,您应该分别发布每个问题),但这里介绍了如何处理第一个问题,它还可以帮助您处理其余问题

import pandas as pd
ht = """[your html]"""
targets = ['Change', 'Status', 'Req._Type']
df = pd.read_html(ht)[1]

for target in targets:
    print(df[target].value_counts())
    print('---')
输出:

NEW OBJECT                         2
Attribute "Object Text" Changed    1
OBJECT DELETED                     1
Name: Change, dtype: int64
---
In Review    3
Name: Status, dtype: int64
---
Info.              2
functional Req.    1
Name: Req._Type, dtype: int64

谢谢你,杰克·弗利廷。我有它,包括如何打印是作为文件输出。关于其他查询,如何计算耦合值(过滤掉)的数量,即“功能需求和对象新”?我还没有找到答案。@FafnerNormanko试着把它作为一个单独的问题发布;也许会有帮助。谢谢你@Jack Fleeting。我有它,包括如何打印是作为文件输出。关于其他查询,如何计算耦合值(过滤掉)的数量,即“功能需求和对象新”?我还没有找到答案。@FafnerNormanko试着把它作为一个单独的问题发布;这可能会有帮助。