# Column values from CSV arranged in a grid

**URL:** <https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794>\
**Category:** Coding Questions\
**Created:** [February 13, 2021, 3:04pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794 "2021-02-13T15:04:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:04pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/1 "2021-02-13T15:04:49Z")

</div>

Hi there

I’ve been using Processing for years, but am stumped by what I think might be quite simple - I have searched but with no luck.

My aim is to take a list of string values from a column in a CSV and arrange them in a grid.

I can make a grid using for loops (as in code below), but all that happens in a nested loop is it repeats the first ten values.

For the sake of argument, let’s say the CSV has 100 rows. What I want to happen is the second row starts with the eleventh value from the CSV and we fill out the 10x10 grid with the 100 strings from the CSV.

Here’s where I’m upto:

```auto
Table table;
void setup() {
  size(600, 600);
  noLoop();
  table = loadTable("data.csv", "header");
}
void draw() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
       text(table.getString(i, 3), 100 + i * 20, 100 + j * 20);
    }
  }
}

```

Hopefully someone get’s what I mean and can point me in the right direction… many thanks 🙂 Michael

Also… I have tried a variety of tricks using the i and j values (see below code snippet) to increment but am not quite there yet…

` text((1 + i) * (1 + j), 100 + i * 20, 100 + j * 20);`

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 3:28pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/2 "2021-02-13T15:28:56Z")

</div>

Does the csv have 10 columns?

```auto
text(table.getString(i, 3)

```

Why 3, what about

```auto
text(table.getString( j, i) .....   

```

[https://www.processing.org/reference/Table\_getString\_.html](https://www.processing.org/reference/Table_getString_.html)

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:30pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/3 "2021-02-13T15:30:14Z")

</div>

Maybe a simpler way of looking at the problem is I’d like to arrange the numbers 1 - 100 consecutively in a 10x10 grid. Sample code (that isn’t quite right) below:

```auto
void setup() {
  size(600, 600);
  noLoop();
}
void draw() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      text(i + j, 100 + i * 20, 100 + j * 20);
    }
  }
}

```

It seems like it should be easy - hence me asking!

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:33pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/4 "2021-02-13T15:33:05Z")

</div>

Hey thanks, for that I don’t want to replicate the layout of the CSV, I want to arrange the contents of one column in a grid. I just posted another code sample that may explain my query a bit better 🙂

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 3:34pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/5 "2021-02-13T15:34:37Z")

</div>

Ah, then let a 3rd variable `k` run, use `k` in getString [` text(table.getString(k, 3), ...`]

say `k++;`

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:40pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/6 "2021-02-13T15:40:05Z")

</div>

Amazing, thankyou! Just the prompt I needed. I’ve now got the 1 - 100 problem sorted (code below). I can extrapolate this to my CSV thing. Thanks for the help! 🙂

```auto
int k = 1;

void setup() {
  size(600, 600);
  noLoop();
}

void draw() {
  for (int j = 0; j < 10; j++) {
    for (int i = 0; i < 10; i++) {
      text(k, 100 + i * 20, 100 + j * 20);
      k++;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 3:41pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/7 "2021-02-13T15:41:06Z")

</div>

Hey, and welcome to the forum!

Great to have you here!

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:42pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/8 "2021-02-13T15:42:31Z")

</div>

Thanks, I’ve been using Processing for years - can’t believe I’ve never asked a question here (I’d have probably saved a few years worth of googling)… 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 3:47pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/9 "2021-02-13T15:47:01Z")

</div>

k can be local (in draw()) and can / should start with 0 I guess

```auto
void draw() {
  int k = 0;
  for (int j = 0;

```

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 13, 2021, 3:47pm UTC](https://discourse.processing.org/t/column-values-from-csv-arranged-in-a-grid/27794/10 "2021-02-13T15:47:50Z")

</div>

Yeah I guessed that for the CSV thanks, just wanted the 1-100 solution to be nice and clean 🙂
