# How to get column names and values from Google Sheets in Python Code node n8n?

**URL:** <https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603>\
**Category:** Questions\
**Tags:** core, node, code\
**Created:** [May 23, 2026, 8:15am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603 "2026-05-23T08:15:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quent](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/quent/32/175176_2.png) [@Quent](https://community.n8n.io/u/Quent)\
**Post date:** [May 23, 2026, 8:15am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/1 "2026-05-23T08:15:15Z")

</div>

I need to loop through all the columns retrieved from Google Sheets and find out their names and values ​​through a code block like this:

```auto
data = _input.all()

for item in data:
    row = item["json"]

    for column_name, value in row.items():
        print(f"Столбец: {column_name}")
        print(f"Значение: {value}")

```

But I got an error saying `_input` doesn’t exist. So how do I loop through all the column names and their values?

---

<div class="post-metadata">

**Author:** ![houda\_ben](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/houda_ben/32/163410_2.png) [@houda\_ben](https://community.n8n.io/u/houda_ben)\
**Post date:** [May 23, 2026, 8:19am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/3 "2026-05-23T08:19:24Z")

</div>

Hi @Quent , welcome !

1. `_input` is Python syntax. If you’re getting “\_input doesn’t exist”, you’re likely in JavaScript mode. Check the Language dropdown at the top of the Code node. In JavaScript, the equivalent is `$input.all()`.

2. `print()` won’t show output. The Code node requires you to return items. `print()` output goes nowhere.

Here’s a working version in JavaScript (Run Once for All Items):

```javascript
const results = [];
for (const item of $input.all()) {
  for (const [columnName, value] of Object.entries(item.json)) {
    results.push({ json: { columnName, value } });
  }
}
return results;

```

Or if you do switch to Python mode ([requires Task Runners](https://docs.n8n.io/code/code-node/), enabled by default in 2.0+):

```python
results = []
for item in _input.all():
    for column_name, value in item.json.items():
        results.append({"json": {"column_name": column_name, "value": value}})
return results

```

Let me know if it works 🤞

---

<div class="post-metadata">

**Author:** ![nguyenthieutoan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nguyenthieutoan/32/120924_2.png) [@nguyenthieutoan](https://community.n8n.io/u/nguyenthieutoan)\
**Post date:** [May 23, 2026, 8:49am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/4 "2026-05-23T08:49:51Z")

</div>

Welcome @Quent to our community! I’m Jay and I am a n8n verified creator.

In n8n’s Python Code node, the variable is `items` (not `_input`). Each item in `items` is a dict with a `json` key. Here’s the corrected version:

```python
for item in items:
    row = item["json"]
    for column_name, value in row.items():
        print(f"Column: {column_name}")
        print(f"Value: {value}")

return items

```

Note: you also need to `return items` at the end of the Code node or it will return nothing downstream.

---

<div class="post-metadata">

**Author:** ![Quent](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/quent/32/175176_2.png) [@Quent](https://community.n8n.io/u/Quent)\
**Post date:** [May 23, 2026, 9:16am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/5 "2026-05-23T09:16:05Z")

</div>

That`s not works. Same error, only with items  
Here my node settings:

 ![Print Screen 2026-05-22 111504](https://europe1.discourse-cdn.com/n8n/original/3X/5/b/5b602613f41af6b7abb47be1b78b7db6e9815e13.png)

---

<div class="post-metadata">

**Author:** ![Quent](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/quent/32/175176_2.png) [@Quent](https://community.n8n.io/u/Quent)\
**Post date:** [May 23, 2026, 9:23am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/6 "2026-05-23T09:23:53Z")

</div>

That also doesn’t work. Same error

---

<div class="post-metadata">

**Author:** ![houda\_ben](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/houda_ben/32/163410_2.png) [@houda\_ben](https://community.n8n.io/u/houda_ben)\
**Post date:** [May 23, 2026, 9:29am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/7 "2026-05-23T09:29:37Z")

</div>

@Quent

Ok, the thing is, for Run Once For Each Item you have to use \_item in singular, the For ALL Items mode you have to use \_items.

so since you’re in Run Once For Each Item mode, try this :

```python
row = _item[“json”]
for column_name, value in row.items():
print(f"Column: {column_name}“)
print(f"Value: {value}”)

return _item

```

---

<div class="post-metadata">

**Author:** ![Quent](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/quent/32/175176_2.png) [@Quent](https://community.n8n.io/u/Quent)\
**Post date:** [May 23, 2026, 9:42am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/8 "2026-05-23T09:42:49Z")

</div>

That`s works! Thank you, @houda_ben

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [May 30, 2026, 9:43am UTC](https://community.n8n.io/t/how-to-get-column-names-and-values-from-google-sheets-in-python-code-node-n8n/296603/9 "2026-05-30T09:43:41Z")

</div>

Closed on May 30, 2026, 9:43am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
