/ getemptydf.jl
getemptydf.jl
 1  using DataFrames
 2  
 3  """
 4  # getemptydf(dataframes-vector)
 5  
 6  Given a **DataFrames Vector** create and return an empty DataFrame with the
 7  same column names as the input (i.e., 0x7 DataFrame).  A **DataFrames Vector**
 8   is a vector of DataFrames, such as: *dfvector = [df1, df2, df3]*.
 9  
10  ## Arguments
11  This function depends on these packages:
12  - DataFrames
13  
14  ## Examples
15  
16  ```julia-repl
17  julia> getemptydf(dataframes-vector)
18  0×42 DataFrame
19   Row │ VAERS_ID  RECVDATE  STATE   AGE_YRS  CAGE_YR  CAGE_MO  SEX     RPT_DATE
20       │ Any       Any       String  Any      Any      Any      String  String  
21  ─────┴───────────────────────────────────────────────────────────────────────
22  
23  ```
24  """
25  function getemptydf(dfvector::Vector{DataFrame})
26      colnames = Symbol.(names(dfvector[1]))
27      #=  The describe() function returns a dataframe that includes an :eltype
28          column containing the data type for each column.
29      =#
30      coltypes = describe(dfvector[1])[:, :eltype]
31      #=  The following constructs named tuples consisting of (column name, data type).
32          EX: (wkt = String[], qualityRatio20 = Float64[], qualityFlag20 = Bool[], ...)
33      =#
34      dfnamedtuple = NamedTuple{Tuple(colnames)}(type[] for type in coltypes)
35      #   Finally create empty DataFrame with desired columns (zero rows)
36      return DataFrame(dfnamedtuple)
37  end