You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could dataframes be read from and output to JSON? I know that pandas and R do it and it's a very universal format. Here are some simple implementations of readjson and writejson using the JSON.jl package.
readjson:
using JSON
using Lazy
using DataFrames
functionreadjson(filename::String)
rawdata = JSON.parsefile(filename)
names =@as file rawdata beginmap(keys,file)
vcat([[i...] for i in file]...)
unique(file)
end
df =DataFrame()
for name in names
df[symbol(name)] =map(rawdata) do obj
haskey(obj,name) ? obj[name] : NA
endfor i in1:length(df[symbol(name)])
if df[symbol(name)][i] ==nothing
df[symbol(name)][i] = NA
endendendreturn df
end
and writejson:
using JSON
using DataFrames
functiondf2json(df::DataFrame)
len =length(df[:,1])
indices =names(df)
jsonarray = [Dict([string(index)=> (isna(df[index][i])? nothing: df[index][i])
for index in indices])
for i in1:len]
return JSON.json(jsonarray)
endfunctionwritejson(path::String,df::DataFrame)
f =open(path,"w")
write(f,df2json(df))
close(f)
end
The text was updated successfully, but these errors were encountered:
Could dataframes be read from and output to JSON? I know that pandas and R do it and it's a very universal format. Here are some simple implementations of
readjson
andwritejson
using the JSON.jl package.readjson:
and writejson:
The text was updated successfully, but these errors were encountered: