首页 > 解决方案 > CSV.write() 不会取任何值

问题描述

我正在尝试将 Julia 数据框导出为 CSV,但它不包含任何值。为了简化假设我有以下数据框:

using DataFrames, CSV

df = DataFrame(A = [nothing,2,3], B = [4,5,nothing])

当我尝试导出时,出现以下错误:

df |> CSV.write("df.csv")

ArgumentError: `nothing` should not be printed; use `show`, `repr`, or custom output instead.

我应该将无值转换为其他值吗?如果是这样,我将如何编码?

标签: julia

解决方案


您可以使用something函数转换nothing为您想要的任何内容(例如missing),如下所示:

something.(df, missing) |> CSV.write("aaa.txt")

此处nothing给出了在编写 CSV 文件时不支持设计的当前原因。


推荐阅读