I am trying to modify two values in a single row of a data frame. However, I get an exception, which I am unable to explain the reason for.
In [1]: import numpy as np
In [2]: import pandas as pd
In [3]: df = pd.DataFrame(np.random.rand(2,3), index=['one', 'two'],
columns=list('ABC'))
In [4]: df['Z'] = list(range(len(df.index)))
In [5]: df.head(1)
Out[5]:
A B C Z
one 0.977917 0.734311 0.069476 0
In [6]: df.iloc[0] = dict(B=3.5, Z=10)
/home/rajatgirotra/tools/miniconda2/envs/shriram/lib/python2.7/site-packages/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value) 525 526 if len(labels) != len(value): --> 527 raise ValueError('Must have equal len keys and value ' 528 'when setting with an iterable') 529
ValueError: Must have equal len keys and value when setting with an iterable
Is this way incorrect? How can I easily modify one or more cell values in the same row?