# CSV Export data lists

**URL:** <https://discourse.mcneel.com/t/csv-export-data-lists/153402>\
**Category:** Grasshopper\
**Tags:** mac\
**Created:** [January 16, 2023, 2:39pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402 "2023-01-16T14:39:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thor2](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thor2/32/603357_2.png) [@Thor2](https://discourse.mcneel.com/u/Thor2)\
**Post date:** [January 16, 2023, 2:39pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/1 "2023-01-16T14:39:32Z")

</div>

Hi there,

I’m trying to export lists using the CSV tool, however can’t work out how to combine them whilst retaining the grouping of data in the second list.  
Essentially the excel I am trying to make is the building name and the facade sizes on that building (For the example’s sake, some buildings have 5 facades, some 3 etc)  
What I’m currently trying to do:

 ![CSV Export](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/9/c/79cb2889fd06da8296a6710600c47e59db0eb047.jpeg)  
The format I understand it should be in post CSV tool for proper export into Excel:  
 ![CSV Export 2](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/8/f/38f984b1cc1f36a28955b02594a4a803af758e79.jpeg)

[CSV Export.gh](https://discourse.mcneel.com/uploads/short-url/9BjJ059S6Fxufnp21facEqoaFcG.gh) (8.2 KB)

Thank you for any help!

---

<div class="post-metadata">

**Author:** ![farouk.serragedine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/farouk.serragedine/32/770975_2.png) [@farouk.serragedine](https://discourse.mcneel.com/u/farouk.serragedine)\
**Post date:** [January 16, 2023, 2:41pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/2 "2023-01-16T14:41:14Z")

</div>

> [@Thor2](#):
>
> I’m trying to export lists using the CSV tool, however can’t work out how to combine them whilst retaining the grouping of data in the second list.

In order to combine two lists while retaining the grouping of data in the second list, you can use the Join method in C#.

Here is an example:

```auto
List<string> list1 = new List<string>() { "A", "B", "C" };
List<string> list2 = new List<string>() { "1", "2", "3" };

var result = list1.Join(list2, x => 1, y => 1, (x, y) => new { x, y });
//This will combine the two lists into a single list of anonymous objects, each containing an element //from list1 and an element from list2.

//You can then use the `result` list to export the data to CSV using CsvHelper library
using (var writer = new StreamWriter("path/to/file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
    csv.WriteRecords(result);
}
File.WriteAllLines("path/to/file.csv", result.Select(x => x.x + "," + x.y));

```

You can make it into a component

---

<div class="post-metadata">

**Author:** ![Thor2](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thor2/32/603357_2.png) [@Thor2](https://discourse.mcneel.com/u/Thor2)\
**Post date:** [January 16, 2023, 2:58pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/3 "2023-01-16T14:58:08Z")

</div>

Thanks @farouk.serragedine … This isn’t working for me currently though. I’m having errors surrounding the list string to join

---

<div class="post-metadata">

**Author:** ![Japhy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/japhy/32/487647_2.png) [@Japhy](https://discourse.mcneel.com/u/Japhy)\
**Post date:** [January 16, 2023, 3:12pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/4 "2023-01-16T15:12:22Z")

</div>

You will need placeholders for the blank items as well as have 3 items in your Headers list.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/e/c/bece318eacc263321a50d27b57a3e481b2976efd.png)

---

<div class="post-metadata">

**Author:** ![Thor2](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thor2/32/603357_2.png) [@Thor2](https://discourse.mcneel.com/u/Thor2)\
**Post date:** [January 16, 2023, 4:04pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/5 "2023-01-16T16:04:26Z")

</div>

Thank you very much @Japhy !

---

<div class="post-metadata">

**Author:** ![Thor2](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thor2/32/603357_2.png) [@Thor2](https://discourse.mcneel.com/u/Thor2)\
**Post date:** [January 16, 2023, 5:08pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/6 "2023-01-16T17:08:06Z")

</div>

Sorry @Japhy , is there a way to add placeholders to multiple branches at once? I have a list with 41 branches and each have a variety of numbers inside (range from 4 to 14), So would ideally would look for a way of automating this addition of placeholders rather than manually enter them!

(This is the list I am trying to input into the solution you gave above):

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/6/6/36679080c9e0aadac101c821c05fff9e731a3c7b.png)

Thanks again for any help

---

<div class="post-metadata">

**Author:** ![magicteddy](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@magicteddy](https://discourse.mcneel.com/u/magicteddy)\
**Post date:** [January 16, 2023, 5:14pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/7 "2023-01-16T17:14:18Z")

</div>

Hi,

Something like this should do the job :

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/8/a/38ac294d62a170a5d53f659c4283eee35d14d34f.png)

[CSV Export.gh](https://discourse.mcneel.com/uploads/short-url/lduv4ntn24aZzVJYPTsxbArflFt.gh) (13.7 KB)

---

<div class="post-metadata">

**Author:** ![Japhy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/japhy/32/487647_2.png) [@Japhy](https://discourse.mcneel.com/u/Japhy)\
**Post date:** [January 16, 2023, 5:30pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/8 "2023-01-16T17:30:30Z")

</div>

Note that MagicTeddy doesn’t pass items through the Text Panel, this can be dangerous when working with floats… 1.2020202

---

<div class="post-metadata">

**Author:** ![Thor2](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thor2/32/603357_2.png) [@Thor2](https://discourse.mcneel.com/u/Thor2)\
**Post date:** [January 16, 2023, 5:47pm UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/9 "2023-01-16T17:47:28Z")

</div>

Thanks both - Found the solution I needed. Much Appreciated!

---

<div class="post-metadata">

**Author:** ![Calcman](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/calcman/32/483097_2.png) [@Calcman](https://discourse.mcneel.com/u/Calcman)\
**Post date:** [November 14, 2023, 11:25am UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/10 "2023-11-14T11:25:49Z")

</div>

How do you write the data to a CSV file? So far i’ve only found panel → stream data. Looking for a way to write the file into a directory with a button.

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [April 15, 2024, 11:01am UTC](https://discourse.mcneel.com/t/csv-export-data-lists/153402/11 "2024-04-15T11:01:26Z")

</div>

OP used a plug-in called LunchBox.
