作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对名为“电影”的表格有疑问。我发现日期和电影标题都在标题栏中。如图所示:
我不知道如何处理这类问题。因此,我尝试使用这段代码使其类似于 MySQL 代码,但无论如何我都没有工作。
DataFrame(row.str.split(' ',-1).tolist(),columns = ['title','date'])
如何将它分成两列(标题、日期)?
最佳答案
如果您使用的是 MySQL 8+,那么我们可以尝试使用 REGEXP_REPLACE
:
SELECT
REGEXP_REPLACE(title, '^(.*)\\s\\(.*$', '$1') AS title,
REGEXP_REPLACE(title, '^.*\\s\\((\\d+)\\)$', '$1') AS date
FROM yourTable;
这是一个可以匹配您的标题字符串的通用正则表达式模式:
^.*\s\((\d+)\)$
解释:
^ from the start of the string
(.*)\s match and capture anything, up to the last space
\( match a literal opening parenthesis
(\d+) match and capture the year (any number of digits)
\) match a literal closing parenthesis
$ end of string
关于mysql - 如何将一列拆分为两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55555068/
我是一名优秀的程序员,十分优秀!