# Python Script (Labs) – Execute failed: Duplicate key detected: "0"

**URL:** <https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901>\
**Category:** KNIME Analytics Platform\
**Tags:** python\
**Created:** [May 12, 2022, 3:36pm UTC](https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901 "2022-05-12T15:36:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Essen](https://forum-cdn.knime.com/user_avatar/forum.knime.com/christian_essen/32/37294_2.png) [@Christian\_Essen](https://forum.knime.com/u/Christian_Essen)\
**Post date:** [May 12, 2022, 3:36pm UTC](https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901/1 "2022-05-12T15:36:29Z")

</div>

Hello,

When running my Python script, I get the following error message:  
_ERROR Python Script (Labs) 5:7 Execute failed: org.knime.core.util.DuplicateKeyException: Duplicate key detected: “0”_

In PyCharm the script works without problems and also the execution (“Execute script”) in the node configuration window works without problems. My guess is that there is a problem with the output table, since I call it in a function:

```auto
def main():
     ....
     complete_results = pd.concat(complete_results)
     knio.output_tables[0] = knio.write_table(complete_results)*

main()

```

Any ideas?  
I am thankful for any help!

Christian

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [May 12, 2022, 4:22pm UTC](https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901/2 "2022-05-12T16:22:18Z")

</div>

@Christian_Essen could it be that you might have duplicate IDs (RowIDs) in your data set. You might have to reset the data frame index within the Python node:

> [@Error in Python script node](https://forum.knime.com/t/error-in-python-script-node/41439/6):
>
> Hello @mohini1329 and welcome to the KNIME forum. Have you tried to reset the index values to your DF? df = pd.concat([df.reset\_index(drop=True)], axis=1).copy() BR

> **[KNIME and Python - handle index columns and row\_id – mlauber71](https://hub.knime.com/mlauber71/spaces/Public/kn_example_python_index_rowid~1D47JLruXBjh8eRr/current-state)**
>
> KNIME and Python - handle index columns and row\_id Python script would convert the KNIME RowID to pandas data frame index

---

<div class="post-metadata">

**Author:** ![Christian\_Essen](https://forum-cdn.knime.com/user_avatar/forum.knime.com/christian_essen/32/37294_2.png) [@Christian\_Essen](https://forum.knime.com/u/Christian_Essen)\
**Post date:** [May 13, 2022, 11:12am UTC](https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901/3 "2022-05-13T11:12:56Z")

</div>

Hi Martin,

Thank you very much – tackling the duplicate IDs (RowIDs) did the trick. I did this directly in the Python script and inserted _ignore\_index=True_.  
The script now looks like this

```auto
> def main():
> ....
> complete_results = pd.concat(complete_results, ignore_index=True)
> knio.output_tables[0] = knio.write_table(complete_results)
> 
> main()

```

Thank you again and best regards  
Christian

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 20, 2022, 11:13am UTC](https://forum.knime.com/t/python-script-labs-execute-failed-duplicate-key-detected-0/42901/4 "2022-05-20T11:13:20Z")

</div>

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