# How to add metadata info to a DataFrame?

**URL:** https://discourse.julialang.org/t/how-to-add-metadata-info-to-a-dataframe/11168
**Category:** Data
**Tags:** dataframes, metadata
**Created:** [May 26, 2018, 3:21pm UTC](https://discourse.julialang.org/t/how-to-add-metadata-info-to-a-dataframe/11168 "2018-05-26T15:21:35Z")
**Posts on this page:** 1
**Showing post:** 73

<div class="post-metadata">

### Author: ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)
#### Post date: [May 29, 2018, 1:38pm UTC](https://discourse.julialang.org/t/how-to-add-metadata-info-to-a-dataframe/11168/73 "2018-05-29T13:38:08Z")

</div>

OK, let’s summarize a little bit:

- Adding metadata to `DataFrame` (or similar structures) is very useful;
- There is no point (by now) in trying to attach semantic meaning to metadata. The best we can do is to appropriately propagate metadata through copies/slices/views, and discard metadata when more complicated transformations are involved;
- Two approaches can be envisioned: adding metadata to the `DataFrame` (or similar structures) as a whole, or attach them to individual `Arrays`. Both have pros and cons, but likely we will need both;
- By now, a reasonable way to store metadata is a `Dict{Symbol, Any}`, regardless of the followed approach;
- Concerning the implementation with `DataFrames`:
  - there is a [PR](https://github.com/JuliaData/DataFrames.jl/pull/1413) to encapsulate metadata within a `DataFrame` structure, both at a global and column level. The flaw in this implementation is that the metadata, stored in the `colmeta` field of the `DataFrame` structure, do not add any functionality to the package itself. It would be much better to leave the `DataFrames` package as it currently is and _wrap_ it in a container along with metadata;
  - I tried the wrapping approach [here](https://drive.google.com/file/d/1RW4VpkbYsjbiIzuETJ_0Q0lHio-7cuC7/view?usp=sharing), but it turns out there is a lot of boilerplate code to be written;
  - the difficulty in extending the `DataFrame` object **may** ultimately lies in the way the package has been implemented. E.g., the function `Base.getindex(df::DataFrame, col_ind::ColumnIndex)` in the package should actually accept an `AbstractDataFrame` as input, not a `DataFrame`. Moreover the `SubDataFrame` struct inherits from `AbstractDataFrame`, but the `SubDataFrame` and `DataFrame` structures do not share the same fields.
  - I am not sure these are **issues** or intended design decisions for the `DataFrames` package, but they don’t allow the `DataFrame` code to be easily re-used (see [here](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231/4) for a discussion on code reusing by means of composition).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-add-metadata-info-to-a-dataframe/11168)._
