Shortcuts

torcharrow.列

torcharrow.column(data: Optional[Union[Iterable, DType]] = None, dtype: Optional[DType] = None, device: str = '')

创建一个 TorchArrow 列。在设备或默认设备上分配内存。

Parameters:
  • data (数组形式可迭代对象) – 定义列的内容。

  • dtype (dtype, 默认 None) – 强制指定的数据类型。如果为 None,则尽可能自动推断类型。

  • device (Device, 默认 "") – 设备选择从范围中使用哪个运行时。TorchArrow 支持多个运行时(CPU 和 GPU)。如果未提供,则使用 Velox 向量化运行时。有效值为“cpu”(Velox)、“gpu”(即将推出)。

示例

使用自动推断类型创建列:

>>> import torcharrow as ta
>>> s = ta.column([1,2,None,4])
>>> s
0  1
1  2
2  None
3  4
dtype: Int64(nullable=True), length: 4, null_count: 1

创建一个具有任意数据类型的列,这里是一个不可为空的列,包含任意长度的不可为空字符串列表:

>>> sf = ta.column([ ["hello", "world"], ["how", "are", "you"] ], dtype =dt.List(dt.string))
>>> sf.dtype
List(item_dtype=String(nullable=False), nullable=False, fixed_size=-1)

创建一个平均气候数据的列,每个大陆一张地图, 以城市为键,显示每年的平均最低和最高温度:

>>> mf = ta.column([
>>>     {'helsinki': [-1.3, 21.5], 'moscow': [-4.0,24.3]},
>>>     {'algiers':[11.2, 25.2], 'kinshasa':[22.2,26.8]}
>>>     ])
>>> mf
0  {'helsinki': [-1.3, 21.5], 'moscow': [-4.0, 24.3]}
1  {'algiers': [11.2, 25.2], 'kinshasa': [22.2, 26.8]}
dtype: Map(string, List(float64)), length: 2, null_count: 0