0

I'm copying data from one column to another (along the same row) in a pandas DataFrame and instead of displaying the data, the cell reads 'Ellipsis'. It does not even use ellipsis as a punctuation i.e '...', it just says 'Ellipsis'. I tried increasing the column width but that didn't help. How do I get the cell to display the data that I copied? This is the code I've been using:

data['Upper Body'][data['Lower Body Color'].str.startswith('upperBody')] = data['Lower Body Color'][data['Lower Body Color'].str.startswith('upperBody')]
Rohan Raj
  • 55
  • 1
  • 7
  • 1
    This might be a dumb question, but does your original data contain 'Ellipsis' as a value? I've never encountered this.... – aiguofer Oct 23 '16 at 14:40
  • Also, what environment are you in; Standard REPL, IPython, Jupyter, some IDE? – aiguofer Oct 23 '16 at 14:44
  • @aiguofer No man, the original data has strings, none of which reads Ellipsis. And I'm on Jupyter. – Rohan Raj Oct 23 '16 at 15:11
  • @Rohan_Raj So in Jupyter, it could be a config within Jupyter itself (some css styling or something), but it could also be the pandas config. Have you tried playing around with `display.max_colwidth` in Pandas? (see more at http://pandas.pydata.org/pandas-docs/stable/options.html). Or do you have any extensions or other customizations in Jupyter? – aiguofer Oct 23 '16 at 18:18
  • @aiguofer I did all I could with the pd.get_option() commands. Still nothing. There are no extensions as such in my Jupyter and I'm using it as it came with Anaconda. Here is the code that's causing this to happen: data['Upper Body'][data['Lower Body Color'].str.startswith('upperBody')] = data['Lower Body Color'][data['Lower Body Color'].str.startswith('upperBody')] – Rohan Raj Oct 24 '16 at 15:55
  • @Rohan_Raj maybe it's due to some weirdness with setting values on slices.... could you try this instead: `data.ix[data['Lower Body Color'].str.startswith('upperBody'), 'Upper Body'] = data['Lower Body Color'][data['Lower Body Color'].str.startswith('upperBody')]` – aiguofer Oct 24 '16 at 16:24
  • Works like a charm! Thanks! What was I doing wrong? – Rohan Raj Oct 24 '16 at 16:55
  • Great!, could you edit the original question adding the code you were using and I'll add an answer explaining what was happening. You can then please accept my answer :) – aiguofer Oct 24 '16 at 17:00

1 Answers1

0

The issue you're having is in how you're copying the data to a df slice. When you select a slice in Pandas, internally it sometimes creates a copy and sometimes just holds a reference to the original object. This makes it tricky when you're trying to set values for a slice of the data.

The most reliable way to set values on slices is by using ix, in your case:

data.ix[data['Lower Body Color'].str.startswith('upperBody'), 'Upper Body'] = data['Lower Body Color'][data['Lower Body Color'].str.startswith('upperBody')]

See more here

Community
  • 1
  • 1
aiguofer
  • 1,887
  • 20
  • 34