qgrid icon indicating copy to clipboard operation
qgrid copied to clipboard

AttributeError when displaying DataFrame with duplicate column names

Open trankmichael opened this issue 7 years ago • 3 comments
trafficstars

Environment

  • Operating System:
  • Python Version: 2.7.6
  • How did you install Qgrid: pip
  • Python packages: qgrid==1.0.5, jupyterlab==0.32.1, notebook==5.3.1
  • Jupyter lab packages (if applicable): jupyterlab-manager v0.35.0, qgrid v1.0.5

Description of Issue

  • What did you expect to happen? I expected to view the DataFrame similar to __repr_html__.

  • What happened instead? AttributeError: 'DataFrame' object has no attribute 'map' in _update_table. It looks like the function expects a Series. There are no errors with integer values in the DataFrame, but values are dropped.

Reproduction Steps

# works but 'sdfa' , 'asda' is lost when the index is reset 
w = pd.DataFrame([['sdfa', 2],['asda', 3], ['asda', 3]], columns=['a','a'])

#only keeps the right most column 
x = pd.DataFrame([[3, 1, 1],[2, 1, 1], [2, 3, 1]], columns=['a','a','a'])

# AttributeError: 'DataFrame' object has no attribute 'map' in _update_table
y = pd.DataFrame([['abc','def'],['def', 'abc']], columns=['a','a'])

# AttributeError: 'DataFrame' object has no attribute 'map' in _update_table
z = pd.DataFrame([[3, 'sdfa'],[2, 'asda']], columns=['a','a'])

qgrid.show_grid(z)

What steps have you taken to resolve this already?

Maybe something like the suffix in pandas.merge can be added on initialization of DataFrames with duplicate names.

>>> A.merge(B, left_on='lkey', right_on='rkey', how='outer')
   lkey  value_x  rkey  value_y
0  foo   1        foo   5
1  foo   4        foo   5
2  bar   2        bar   6
3  bar   2        bar   8
4  baz   3        NaN   NaN
5  NaN   NaN      qux   7

trankmichael avatar Jun 08 '18 17:06 trankmichael

I was able to reproduce this, thanks for the report. Hopefully I can get to it soon but because the workaround is pretty straightforward (renaming the columns with duplicate names) I'm going to finish up some higher priority work before I get to this.

TimShawver avatar Jun 10 '18 05:06 TimShawver

Another problem is the cryptic error-message object has no attribute 'map'.

ankostis avatar Oct 11 '18 17:10 ankostis

@ankostis I had the same problem. It happens when in the dataframe there are two columns with the same name. It disappeard when I deleted a duplicate column, not sure how because I didn't investigate on the functionality.

foebu avatar Jun 28 '20 17:06 foebu