字符串修改#

修改

枚举类型

枚举类 side_type#

cudf::strings::stripcudf::strings::pad 函数的方向标识符。

枚举成员 LEFT#

从字符串开头移除/填充字符

枚举成员 RIGHT#

从字符串末尾移除/填充字符

枚举成员 BOTH#

从字符串开头和末尾移除/填充字符

枚举类 class filter_type : bool#

cudf::strings::filter_characters 中移除或保留指定的字符范围。

枚举成员 KEEP#

除了指定的字符外,所有其他字符都被移除。

枚举成员 REMOVE#

只有指定的字符被移除。

函数

std::unique_ptr<column> pad(strings_column_view const &input, size_type width, side_type side = side_type::RIGHT, std::string_view fill_char = " ", rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

使用提供的字符为每个字符串添加填充。

如果字符串长度已达到或超过 width 个字符,则不进行填充。同时,不会截断任何字符串。

空字符串条目在输出列中产生相应的空条目。

Example:
s = ['aa','bbb','cccc','ddddd']
r = pad(s,4)
r is now ['aa  ','bbb ','cccc','ddddd']
参数:
  • input – 用于此操作的字符串实例

  • width – 每个字符串的最小字符数

  • side – 填充字符的位置;默认是右侧填充(左对齐)

  • fill_char – 用于填充的单个 UTF-8 字符;默认是空格字符

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源

返回值:

包含填充字符串的新列

std::unique_ptr<column> zfill(strings_column_view const &input, size_type width, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

在每个字符串的左侧添加 ‘0’ 作为填充。

这等同于 pad(width,left,’0`),但会保留出现在第一个位置的符号字符。

如果字符串长度已达到或超过 width 个字符,则不进行填充。不会截断任何字符串。

输入中的空行在输出列中产生相应的空行。

Example:
s = ['1234','-9876','+0.34','-342567', '2+2']
r = zfill(s,6)
r is now ['001234','-09876','+00.34','-342567', '0002+2']
参数:
  • input – 用于此操作的字符串实例

  • width – 每个字符串的最小字符数

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源

返回值:

新字符串列

std::unique_ptr<column> reverse(strings_column_view const &input, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

反转每个字符串内的字符。

任何空字符串条目都会返回相应的空输出列条目。

Example:
s = ["abcdef", "12345", "", "A"]
r = reverse(s)
r is now ["fedcba", "54321", "", "A"]
参数:
  • input – 用于此操作的字符串列

  • mr – 用于分配返回列设备内存的设备内存资源

  • stream – 用于设备内存操作和内核启动的 CUDA 流

返回值:

新字符串列

std::unique_ptr<column> strip(strings_column_view const &input, side_type side = side_type::BOTH, string_scalar const &to_strip = string_scalar(""), rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

从每个字符串的开头或结尾(或两者)移除指定的字符。

`to_strip` 参数可以包含一个或多个字符。`to_strip` 中的所有字符都将从输入字符串中移除。

如果 to_strip 是空字符串,则移除空白字符。空白字符被认为是空格字符以及制表符和换行符等控制字符。

任何空字符串条目都会返回相应的空输出列条目。

Example:
s = [" aaa ", "_bbbb ", "__cccc  ", "ddd", " ee _ff gg_"]
r = strip(s,both," _")
r is now ["aaa", "bbbb", "cccc", "ddd", "ee _ff gg"]
抛出:

cudf::logic_error – 如果 to_strip 无效。

参数:
  • input – 用于此操作的字符串列

  • side – 指示从每个字符串的开头、结尾或两者移除字符;默认是两者

  • to_strip – 要从每个字符串中移除的 UTF-8 编码字符;默认是空字符串,表示移除空白字符

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源。

返回值:

新字符串列。

std::unique_ptr<column> translate(strings_column_view const &input, std::vector<std::pair<char_utf8, char_utf8>> const &chars_table, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

转换每个字符串中的单个字符。

这也可以通过为相应的表格条目指定 0 来用于移除字符。

空字符串条目在输出列中产生空条目。

Example:
s = ["aa","bbb","cccc","abcd"]
t = [['a','A'],['b',''],['d':'Q']]
r = translate(s,t)
r is now ["AA", "", "cccc", "AcQ"]
参数:
  • input – 用于此操作的字符串实例

  • chars_table – UTF-8 字符映射表

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源

返回值:

包含填充字符串的新列

std::unique_ptr<column> filter_characters(strings_column_view const &input, std::vector<std::pair<cudf::char_utf8, cudf::char_utf8>> characters_to_filter, filter_type keep_characters = filter_type::KEEP, string_scalar const &replacement = string_scalar(""), rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

从字符串列中的每个字符串移除字符范围。

这也可以用于仅保留指定的字符范围,并从每个字符串中移除所有其他字符。

Example:
s = ["aeiou", "AEIOU", "0123456789", "bcdOPQ5"]
f = [{'M','Z'}, {'a','l'}, {'4','6'}]
r1 = filter_characters(s, f)
r1 is now ["aei", "OU", "456", "bcdOPQ5"]
r2 = filter_characters(s, f, REMOVE)
r2 is now ["ou", "AEI", "0123789", ""]
r3 = filter_characters(s, f, KEEP, "*")
r3 is now ["aei**", "***OU", "****456***", "bcdOPQ5"]

空字符串条目在输出列中产生空条目。

抛出:

cudf::logic_error – 如果 replacement 无效

参数:
  • input – 用于此操作的字符串实例

  • characters_to_filter – 要过滤的字符范围表

  • keep_characters – 如果为 true,则保留 characters_to_filter 中的字符,并移除所有其他字符

  • replacement – 每个移除字符的可选替换字符串

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源

返回值:

包含过滤后字符串的新列

std::unique_ptr<column> wrap(strings_column_view const &input, size_type width, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

通过用换行符(ASCII 0x0A)替换适当的空白,将字符串换行到多行,使每行短于 width

对于输入列中每个长于 width 的字符串行,相应的输出字符串行将插入换行符,以使每行不超过 width 字符。尝试使用现有空白位置来分割字符串,但在必要时也可能分割非空白序列。

任何空字符串条目都会返回相应的空输出列条目。

示例 1

width = 3
input_string_tbl = [ "12345", "thesé", nullptr, "ARE THE", "tést strings", "" ];

wrapped_string_tbl = wrap(input_string_tbl, width)
wrapped_string_tbl = [ "12345", "thesé", nullptr, "ARE\nTHE", "tést\nstrings", "" ]

示例 2

width = 12;
input_string_tbl = ["the quick brown fox jumped over the lazy brown dog", "hello, world"]

wrapped_string_tbl = wrap(input_string_tbl, width)
wrapped_string_tbl = ["the quick\nbrown fox\njumped over\nthe lazy\nbrown dog", "hello, world"]

参数:
  • input – 字符串列

  • width – 每个字符串中行的最大字符宽度

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配返回列设备内存的设备内存资源

返回值:

换行后的字符串列