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

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

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

问题

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

代码

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

输入模式

- dec: array
-- element: struct
    |-- Offset: choice
    |    |-- long
    |    |-- string

当前输出模式

- dec: array
-- element: struct
    |-- Offset: choice
    |    |-- long
    |    |-- string

预期输出模式

dec: array
-- element: struct
    |-- 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

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

Input schema

- dec: array
-- element: struct
    |-- Offset: choice
    |    |-- long
    |    |-- string

Current Output Schema

- dec: array
-- element: struct
    |-- Offset: choice
    |    |-- long
    |    |-- string

Expected Output Schema

dec: array
-- element: struct
    |-- Offset: long

答案1

得分: 0

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

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

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

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:

确定