# Error in Python script node

**URL:** <https://forum.knime.com/t/error-in-python-script-node/41439>\
**Category:** KNIME Analytics Platform\
**Created:** [April 7, 2022, 9:58am UTC](https://forum.knime.com/t/error-in-python-script-node/41439 "2022-04-07T09:58:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohini1329](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mohini1329/32/31516_2.png) [@mohini1329](https://forum.knime.com/u/mohini1329)\
**Post date:** [April 7, 2022, 9:58am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/1 "2022-04-07T09:58:47Z")

</div>

I have used a Python scripting within my KNIME workflow. Within the configuration window, the code runs successfully but throws and error when trying to actually run the node. _Execute failed: Output DataFrame contains duplicate values in its index: ‘0’, ‘1’, ‘2’, and others. This is not supported. Please make sure that each entry in the index (i.e., each row key) is unique._ Can you please help me with the solution.

---

<div class="post-metadata">

**Author:** ![ActionAndi](https://forum-cdn.knime.com/user_avatar/forum.knime.com/actionandi/32/76198_2.png) [@ActionAndi](https://forum.knime.com/u/ActionAndi)\
**Post date:** [April 7, 2022, 11:38am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/2 "2022-04-07T11:38:02Z")

</div>

Hi,  
your DataFrame has probably duplicate index entries.  
Try  
`df.reset_index(inplace=True)`

---

<div class="post-metadata">

**Author:** ![elsamuel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@elsamuel](https://forum.knime.com/u/elsamuel)\
**Post date:** [April 7, 2022, 2:09pm UTC](https://forum.knime.com/t/error-in-python-script-node/41439/3 "2022-04-07T14:09:16Z")

</div>

Are your row keys unique?

---

<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:** [April 8, 2022, 5:16am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/4 "2022-04-08T05:16:06Z")

</div>

@mohini1329 welcome to the KNIME forum. You might want to store a unique rowid before using the [(new) python node](https://kni.me/n/dQ5A2CMdtDriX4ro).

> **[RowID](https://hub.knime.com/knime/extensions/org.knime.features.base/latest/org.knime.base.node.preproc.rowkey2.RowKeyNodeFactory2)**
>
> This node can be used to replace the RowID of the input data with the values of another column (by converting the values to a string) or a generated row id of …

> **[Workflows: Rowid – KNIME Hub](https://hub.knime.com/search?type=Workflow&tag=Rowid&sort=maxDownloads)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

Also you should maybe [store this Rowid](https://kni.me/w/9hRISlxbpxxO-9h9) and later check if you have done the right transformations.

I just encountered a thing when using thre python nodes that you might run into problems when you do joins but did not reset the index within the python node since KNIME would use the rowid as index seemingly.

---

<div class="post-metadata">

**Author:** ![carstenhaubold](https://forum-cdn.knime.com/user_avatar/forum.knime.com/carstenhaubold/32/33947_2.png) [@carstenhaubold](https://forum.knime.com/u/carstenhaubold)\
**Post date:** [April 8, 2022, 7:06am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/5 "2022-04-08T07:06:47Z")

</div>

Hi @mohini1329,

as the others have already suggested, you should make sure that each row in the Pandas DataFrame has a unique index.

Dropping/resetting the index is not the best option though, because KNIME uses the RowID (which is equal to the DataFrame index) to identify rows when you select / highlight individual cells in your data. If you reset the index, then this row identification will no longer work.  
The best solution would be to let the index of all values in your input table as they are, but assign new unique indices (which are actually string based) to all new rows that you add.

@mlauber71: the RowID node that you mentioned has the same problem if “enable hiliting” is disabled.

If you do not care about selection/hiliting, then dropping the index is fine, though 🙂

Hope that helps,  
Carsten

---

<div class="post-metadata">

**Author:** ![gonhaddock](https://forum-cdn.knime.com/user_avatar/forum.knime.com/gonhaddock/32/35425_2.png) [@gonhaddock](https://forum.knime.com/u/gonhaddock)\
**Post date:** [April 8, 2022, 7:20am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/6 "2022-04-08T07:20:26Z")

</div>

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

---

<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:** [April 8, 2022, 11:47am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/7 "2022-04-08T11:47:44Z")

</div>

@carstenhaubold, @mohini1329 I have created an example where the RowID is handled and reset and applied from within the Pandas dataframe.

I think it would be good to mention the handling of the RowIDs somehwere in then Python documentation. And also one should be aware that if you copy a dataframe the index might also be resetted. So we should be careful with that.

> **[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

What would be great is a Counter node that would support Long (integers) to handle very large data sets.

–  
Edit: [KNIME and Python — Setting up and managing Conda environments | by Markus Lauber | Low Code for Data Science | Medium](https://medium.com/low-code-for-advanced-data-science/knime-and-python-setting-up-and-managing-conda-environments-2ac217792539)

---

<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:** [July 7, 2022, 11:47am UTC](https://forum.knime.com/t/error-in-python-script-node/41439/8 "2022-07-07T11:47:55Z")

</div>

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