1
votes

I imported a table from a SQL database into a dataframe, and now I'm trying to get statistics about the dataframe via describe(). I also tried head(). Both return an error "ERROR: UndefVarError: describe not defined".

I've added and imported the DataFrames package to resolve the issue, which didn't work.

This is how I imported the dataframe:

using Pkg

Pkg.add("ODBC")

Pkg.add("DataFrames")

using ODBC, DataFrames

db = ODBC.DSN(connection_string)

query = ODBC.query(db, "SELECT * FROM table")

df = DataFrame(query)

describe(df)

I am expecting a result similar to the describe() or head() Python functions. I would expect columns labels and the first few rows after running head(df). I would expect min, max, avg, count, etc for each of the column labels after running describe(df).

1
Have you also imported Pandas.jl or any other package that provides describe or head? In this case, you need to use fully-qualified names DataFrames.describe and DataFrames.head. This is not necessary in other situations.hckr
Thanks! I'm surprised the Julia page I was reading from didn't mention that anywhere.Nicholas Taylor

1 Answers

2
votes

There is first instead of head. See the code below for a sample:

julia> using DataFrames

julia> df = DataFrame(a=1:5,b=6:10)
5×2 DataFrame
│ Row │ a     │ b     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1   │ 1     │ 6     │
│ 2   │ 2     │ 7     │
│ 3   │ 3     │ 8     │
│ 4   │ 4     │ 9     │
│ 5   │ 5     │ 10    │

julia> first(df,3)
3×2 DataFrame
│ Row │ a     │ b     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1   │ 1     │ 6     │
│ 2   │ 2     │ 7     │
│ 3   │ 3     │ 8     │

julia> describe(df)
2×8 DataFrame
│ Row │ variable │ mean    │ min   │ median  │ max   │ nunique │ nmissing │ eltype   │
│     │ Symbol   │ Float64 │ Int64 │ Float64 │ Int64 │ Nothing │ Nothing  │ DataType │
├─────┼──────────┼─────────┼───────┼─────────┼───────┼─────────┼──────────┼──────────┤
│ 1   │ a        │ 3.0     │ 1     │ 3.0     │ 5     │         │          │ Int64    │
│ 2   │ b        │ 8.0     │ 6     │ 8.0     │ 10    │         │          │ Int64    │