# Sending Dataframes of different lengths to a CSV file

**URL:** <https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [August 1, 2019, 5:58am UTC](https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064 "2019-08-01T05:58:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MuadhF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/muadhf/32/20389_2.png) [@MuadhF](https://discourse.julialang.org/u/MuadhF)\
**Post date:** [August 1, 2019, 5:58am UTC](https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064/1 "2019-08-01T05:58:45Z")

</div>

Hi,

Is there a way to send `DataFrames` of different lengths to a CSV file, so that when I open them in Excel, they would appear side by side?  
Or is there simply a way to create a single `DataFrame` with varying column lengths, so I can just send that to the CSV file?

Right now what I’m doing is just using the `append` kwarg and stacking one dataframe over the other, which isn’t very pretty or convenient. If there is a solution to this please let me know, thanks!

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [August 2, 2019, 3:48am UTC](https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064/2 "2019-08-02T03:48:04Z")

</div>

> [@MuadhF](#):
>
> Is there a way to send `DataFrames` of different lengths to a CSV file, so that when I open them in Excel, they would appear side by side?

Hmmm…this is a pretty non-standard operation; I’m not aware of any way you could do this (in any language, not just Julia).

> [@MuadhF](#):
>
> Or is there simply a way to create a single `DataFrame` with varying column lengths, so I can just send that to the CSV file?

The DataFrames package tries very hard to ensure column lengths are consistent, since it affects many operations: grouping, sorting, indexing, etc.

Part of the issue of what you’re requesting is that the csv file format is row-based, while DataFrames are columnar, which makes it a bit awkward to consider writing out multiple DataFrames side-by-side by rows.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [August 3, 2019, 3:33pm UTC](https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064/3 "2019-08-03T15:33:07Z")

</div>

What you can do is adding rows full of `missing` to the shorter data frame(s) using `vcat` or `append!`, and then concatenate the data frames into a single one using `hcat`.

---

<div class="post-metadata">

**Author:** ![MuadhF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/muadhf/32/20389_2.png) [@MuadhF](https://discourse.julialang.org/u/MuadhF)\
**Post date:** [August 4, 2019, 6:53am UTC](https://discourse.julialang.org/t/sending-dataframes-of-different-lengths-to-a-csv-file/27064/4 "2019-08-04T06:53:02Z")

</div>

Ah alright that makes sense, and yeah I did realise that it probably wouldn’t be possible, but I just wanted to check. Thanks for the explanation!
