maxframe.dataframe.Series.dict.remove#

Series.dict.remove(query_key, ignore_key_error: bool = False)#

从 Series 的每个字典中根据键删除项。

参数:
  • query_key (Any) -- 要删除的键,必须与字典中的键类型相同。

  • ignore_key_error (bool, optional, default False) -- 当 query_key 不在字典中时,如果 ignore_key_error 为 True,则字典中不会发生任何变化。如果 ignore_key_errorFalse,则会抛出 KeyError。如果字典为 None,则返回 None

返回:

具有相同数据类型的 Series。如果字典为 None

返回类型:

Series

抛出:

KeyError : -- 如果 query_key 不在某个字典中且 ignore_key_errorFalse

示例

创建一个包含字典类型数据的 Series。

>>> import maxframe.dataframe as md
>>> import pyarrow as pa
>>> from maxframe.lib.dtypes_extension import dict_
>>> s = md.Series(
...     data=[[("k1", 1), ("k2", 2)], [("k1", 3)], None],
...     index=[1, 2, 3],
...     dtype=map_(pa.string(), pa.int64()),
... )
>>> s.execute()
1    [('k1', 1), ('k2', 2)]
2               [('k1', 3)]
3                      <NA>
dtype: map<string, int64>[pyarrow]
>>> s.dict.remove("k2", ignore_key_error=True).execute()
1    [('k1', 1)]
2    [('k1', 3)]
3           <NA>
dtype: map<string, int64>[pyarrow]