 <p>I think the problem arises because your data file has 5 columns and your <code>names</code> list has 6 elements. To verify, check the first few values in the <code>id</code> column- these will all be set to <code>6</code> if I am right. The First few items in the <code>exp</code> column will have the value <code>3</code>.</p> <p>To fix this, read your input file like so:</p> <pre><code>rs =pd.read_csv('rs.txt', header="infer", sep="\t", names=['exp','fov','cycle', 'color', 'values'], index_col=2 </code></pre> <p>Pandas will automatically insert row identifiers.</p>