我不确定从什么时候开始,但实际上 DataFrame 'Row' 数据类型已经改变。
■previous
Row │ id name sex age ave
│ │ Int32 String String Int32 Float64
│───┼─────────────────────────────────────────────────────────────────
│⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
■recent
Row │ id name sex age ave
│ │ Int32? String? String? Int32? Float64?
│───┼─────────────────────────────────────────────────────────────────
│⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
您可以看到所有“行”数据类型都更改为“?”在它的尾部上。 在以前的版本中,我可以使用 eltype.(eachcol(df)) 获取行数据类型,因为它们只是 'Int32','String'...... 但在最近的情况下,它们是 Union{Nothing,Int32}、Union{Nothing,String}....,这就是为什么 eltype.(..) 没有给出与以前版本类似的期望数据类型。 我的问题是
1.现在如何获得与以前一样的“Row”数据类型? 我的意思是将(?)'Union {Nothing,Int32}'转换为'Int32',无论是在DataFrame上还是通过eltype()
2.可选:您知道“行”数据类型发生变化的原因和原因吗?
非常感谢。
最佳答案
Do you know since and why the 'Row' data type has changed?
首先,请仔细检查您的数据是否不是 Union{Nothing,Int32}
而是 Union{Missing,Int32}
。
这里的 DataFrames.jl 没有任何变化。您的数据读取过程可能已更改,现在它会创建允许其中缺失
值的列。
How can I get the 'Row' data type now alike the previous?
如果要删除列元素类型的 Missing
部分,请执行以下操作:
nonmissingtype.(eltype.(eachcol(df)))
关于dataframe - Julia DataFrame 行数据类型已更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77248586/