Description

Append an id column to BatchOperator. the id can be DENSE or UNIQUE

Parameters

Name Description Type Required? Default Value
appendType append type. DENSE or UNIQUE String “DENSE”
idCol Id column name String “append_id”

Script Example

Code

  1. import numpy as np
  2. import pandas as pd
  3. from pyalink.alink import *
  4. def exampleData():
  5. return np.array([
  6. [1.0, "A", 0, 0, 0],
  7. [2.0, "B", 1, 1, 0],
  8. [3.0, "C", 2, 2, 1],
  9. [4.0, "D", 3, 3, 1]
  10. ])
  11. def sourceFrame():
  12. data = exampleData()
  13. return pd.DataFrame({
  14. "f0": data[:, 0],
  15. "f1": data[:, 1],
  16. "f2": data[:, 2],
  17. "f3": data[:, 3],
  18. "label": data[:, 4]
  19. })
  20. def batchSource():
  21. return dataframeToOperator(
  22. sourceFrame(),
  23. schemaStr='''
  24. f0 double,
  25. f1 string,
  26. f2 int,
  27. f3 int,
  28. label int
  29. ''',
  30. op_type='batch'
  31. )
  32. (
  33. AppendIdBatchOp()
  34. .setIdCol("append_id")
  35. .linkFrom(batchSource())
  36. .print()
  37. )

Result

  1. f0 f1 f2 f3 label append_id
  2. 0 1.0 A 0 0 0 0
  3. 1 2.0 B 1 1 0 1
  4. 2 3.0 C 2 2 1 2
  5. 3 4.0 D 3 3 1 3