Python 正则表达式和 Pandas

标签 python regex

我有一个 html 文本,稍后我想将其转换为 pandas 数据框。

我有一个看起来像这样的文本:

<tr>
   <td -some attributes- >Val1</td>
   <td -some attributes- >Val2</td>
   <td -some attributes- >Val3</td>
</tr>
<tr>
   <td -some attributes- >Val4</td>
   <td -some attributes- >Val5</td>
   <td -some attributes- >Val6</td>
</tr>

我有正则表达式:<td.*>(.*)</td>但它并没有捕获所有的值,它捕获了几乎所有的文本......

在我获取所有内容后,我将其放入数据框中。

那么为什么这个正则表达式没有捕获它应该捕获的值?

最佳答案

You can try like this instead of REGEX - just an opinion

import pandas as pd
movies_table = pd.read_html("xxx.y.com")
movies = movies_table[0] // select the correct table from the tables array.

我得到了这个工作。下面我附上了一个使用示例。

Reading directly table data as DataFrame

关于Python 正则表达式和 Pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43895113/

相关文章:

Python - 匹配列表中单词的字母

python - 获取随机轨道

Java正则表达式: what is "' - "

python - 正则表达式:如何使用不包括数字的空格/连字符捕获单词?

javascript - (?=正则表达式) VS (? :regex)

正则表达式匹配文件名

python - 为什么 scipy.sparse.csc_matrix 不保留我的 np.array 的索引顺序?

c++ - 我可以用 Cython 覆盖 Python 中的 C++ 虚函数吗?

python - Matplotlib 条形图 X 轴标签顺序

Javascript/lodash 过滤数组非常慢