跳转至

Strings(字符串(Strings))

Strings refer to text data.

from pyspark.sql import functions as F

Converting between cases

  • F.initcap(col)
  • F.lower(col)
  • F.upper(col)

Concatenating, splitting

  • F.concat(*cols)
  • F.concat_ws(sep, *cols)
  • F.split(str, pattern)

Substrings

  • F.instr(str, substr)
  • F.locate(substr, str, pos=1)
  • F.substring(str, pos, len)
  • F.substring_index(str, delim, count)

Trimming, padding

  • F.lpad(col, len, pad)
  • F.ltrim(col)
  • F.rpad(col, len, pad)
  • F.rtrim(col)
  • F.trim(col)

Regex

  • F.regexp_extract(str, pattern, idx)
  • F.regexp_replace(str, pattern, replacement)

Misc

  • F.ascii(col)
  • F.base64(col)
  • F.bin(col)
  • F.conv(col, fromBase, toBase)
  • F.decode(col, charset)
  • F.encode(col, charset)
  • F.format_number(col, d)
  • F.format_string(format, *cols)
  • F.hex(col)
  • F.length(col)
  • F.levenshtein(left, right)
  • F.repeat(col, n)
  • F.reverse(col)
  • F.translate(srcCol, matching, replace)
  • F.unbase64(col)
  • F.unhex(col)

中文翻译

字符串(Strings)

字符串(Strings)指文本数据。

from pyspark.sql import functions as F

大小写转换

  • F.initcap(col) — 首字母大写
  • F.lower(col) — 转换为小写
  • F.upper(col) — 转换为大写

拼接与拆分

  • F.concat(*cols) — 拼接
  • F.concat_ws(sep, *cols) — 带分隔符拼接
  • F.split(str, pattern) — 拆分

子字符串

  • F.instr(str, substr) — 查找子串位置
  • F.locate(substr, str, pos=1) — 定位子串
  • F.substring(str, pos, len) — 截取子串
  • F.substring_index(str, delim, count) — 按分隔符截取

修剪与填充

  • F.lpad(col, len, pad) — 左填充
  • F.ltrim(col) — 去除左侧空格
  • F.rpad(col, len, pad) — 右填充
  • F.rtrim(col) — 去除右侧空格
  • F.trim(col) — 去除两侧空格

正则表达式(Regex)

  • F.regexp_extract(str, pattern, idx) — 正则提取
  • F.regexp_replace(str, pattern, replacement) — 正则替换

其他函数(Misc)

  • F.ascii(col) — 获取ASCII码
  • F.base64(col) — Base64编码
  • F.bin(col) — 转换为二进制
  • F.conv(col, fromBase, toBase) — 进制转换
  • F.decode(col, charset) — 解码
  • F.encode(col, charset) — 编码
  • F.format_number(col, d) — 数字格式化
  • F.format_string(format, *cols) — 字符串格式化
  • F.hex(col) — 转换为十六进制
  • F.length(col) — 获取长度
  • F.levenshtein(left, right) — 编辑距离
  • F.repeat(col, n) — 重复字符串
  • F.reverse(col) — 反转字符串
  • F.translate(srcCol, matching, replace) — 字符替换
  • F.unbase64(col) — Base64解码
  • F.unhex(col) — 十六进制解码