Question

The documentation for indexing has few examples of assignment of a non-scalar right hand side.

In this case, I want to modify a subset of my dataframe, and what I did prior to v.13 no longer works.

import pandas as pd
from numpy import *

data = {'me':list('rttti'),'foo': list('aaade'), 'bar': arange(5)*1.34+2, 'bar2': arange(5)*-.34+2}
df = pd.DataFrame(data).set_index('me')

print df

df.loc['r',['bar','bar2']]*=2.0
print df
df.loc['t','bar']*=2.5
# Above fails: ValueError: Must have equal len keys and valuewhen setting with an iterable
print df
df.loc['t',['bar','bar2']]*=2.0
# Above fails: *** InvalidIndexError: Reindexing only valid with uniquely valued Index objects
print df

I want to be able to assign a matrix of values to a matrix of locations using loc or, in this simplifed case, I just want to modify them by some simple operation like multiplication.

The first modification works (the index value is unique), and the others do not, though they give different errors.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top