Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSV.write() won't take nothing values

Tags:

julia

I'm trying to export a Julia dataframe into a CSV and it contains nothing values. To simiplify let's say I have the following dataframe:

using DataFrames, CSV

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

When I try to export, I get the following error:

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

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

Should I convert the nothing values to something else like missing? If so, how would I code this?

like image 718
Dan Riggins Avatar asked Oct 07 '19 22:10

Dan Riggins


1 Answers

You can use something function to convert nothing to whatever you want (e.g. missing) like this:

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

The current reasoning behind the design not to support nothing when writing a CSV file is given here.

like image 61
Bogumił Kamiński Avatar answered Oct 11 '22 15:10

Bogumił Kamiński