如何使用Glue动态数据框架Python将包含多种类型值的列转换为单一数据类型?

huangapple go评论93阅读模式
英文:

How can we cast the column that contains values of multiple types to single data type using glue dynamic dataframe python

问题

如何将包含多种类型值的列转换为单一数据类型。我正在使用 resolveChoice 方法,但仍无法将多种类型转换为单一数据类型,使用 Glue 动态数据框架 Python。

代码

  1. df = df.resolveChoice(specs=[("Offset", "cast:long")])

输入模式

  1. - dec: array
  2. -- element: struct
  3. |-- Offset: choice
  4. | |-- long
  5. | |-- string

当前输出模式

  1. - dec: array
  2. -- element: struct
  3. |-- Offset: choice
  4. | |-- long
  5. | |-- string

预期输出模式

  1. dec: array
  2. -- element: struct
  3. |-- Offset: long
英文:

How can we cast the column that contains values of multiple types to single data type. I am using resolveChoice method but still it doesn't convert the multple types to single data type using glue dynamic dataframe python.

code

  1. df = df.resolveChoice(specs=[("Offset", "cast:long")])

Input schema

  1. - dec: array
  2. -- element: struct
  3. |-- Offset: choice
  4. | |-- long
  5. | |-- string

Current Output Schema

  1. - dec: array
  2. -- element: struct
  3. |-- Offset: choice
  4. | |-- long
  5. | |-- string

Expected Output Schema

  1. dec: array
  2. -- element: struct
  3. |-- Offset: long

答案1

得分: 0

你需要输入属性的完整“路径”:

  1. df = df.resolveChoice(specs=[("dec[].Offset", "cast:long")])
英文:

You need to input the whole "path" of the property:

  1. df = df.resolveChoice(specs=[("dec[].Offset", "cast:long")])

huangapple
  • 本文由 发表于 2023年2月27日 13:00:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定