Attempted answer (I'll be happy to see other attempt from expert-er 
julians):

If the Dict is `d` :
d = Dict{String,Any}(
  "edited"                 => false,
  "num_reports"            => "",
  "author"                 => "operaaa",
  "distinguished"          => "",
  "created"                => 1.413351949e9,
  "over_18"                => false,
  "approved_by"            => "",
  "report_reasons"         => "",
  "domain"                 => "wkrg.com",
  "ups"                    => 1,
  "stickied"               => false
  )

then a DataFrame can be constructed using:
DataFrame(; [symbol(k)=>v for (k,v) in d]...)


the idea is that DataFrame constructor uses keyword arguments, and this 
splats the Dict into arguments after changing column names to symbols.

On Wednesday, October 15, 2014 2:09:01 AM UTC+3, James Kyle wrote:
>
> I'm pulling down a json object that produces a list of Dictionaries.
>
> Each dictionary is a row in the DataFrame with the key representing what I 
> want the column name to be. 
>
> At first, I thought I could just do this:
>
>     DataFrame(dict_data)
>
> this produced a deprecation error:
>
> WARNING: DataFrame(::Dict) is deprecated, use convert(::DataFrame,d::Dict)
>  in DataFrame at /Users/jkyle/.julia/v0.3/DataFrames/src/deprecated.jl:160
> ERROR: `length` has no method matching length(::Nothing)
>  in convert at 
> /Users/jkyle/.julia/v0.3/DataFrames/src/dataframe/dataframe.jl:998
>  in DataFrame at /Users/jkyle/.julia/v0.3/DataFrames/src/deprecated.jl:161
>
>
> So I tried:
>
>     convert(DataFrame, dict_data)
>
> This returns
>
> ERROR: ArgumentError("All columns in Dict must have the same length")
>  in convert at 
> /Users/jkyle/.julia/v0.3/DataFrames/src/dataframe/dataframe.jl:1001
>
>
> What's odd, is I can do something like this:
>
> DataFrame(keys(data))
>
>
> And  it works, but creates an empty row for each column. I find this odd, 
> since the column names are the same.
>
> I feel like I'm missing some "trick" to get this to work.
>
>
> The dictionary I'm importing looks like this. 
>
>  Dict{String,Any} with 39 entries:
>   "edited"                 => false
>   "num_reports"            => ""
>   "author"                 => "operaaa"
>   "distinguished"          => ""
>   "created"                => 1.413351949e9
> ............
>   "over_18"                => false
>   "approved_by"            => ""
>   "report_reasons"         => ""
>   "domain"                 => "wkrg.com"
>   "ups"                    => 1
>   "stickied"               => false
>
>  
>
>
>
>
>

Reply via email to