【发布时间】:2016-11-14 17:57:51
【问题描述】:
我有一个如下所示的表格:
>>> df.head()
Out[13]:
v u
init change integral init change
foo bar
baseline NaN 0.025054 0.858122 0.017930 0.048435 1.091943
a 10.0 0.025042 0.856307 0.017546 0.047815 1.100351
50.0 0.025008 0.856681 0.010052 0.048252 1.056658
b 1.0 0.025045 0.858044 0.015635 0.047135 1.091384
2.0 0.025048 0.855388 0.016115 0.047324 1.087964
现在我想根据列的第二级标签选择列,并将它们四舍五入。
我可以使用 xs: df.xs('init', 1, 1) 访问它们。但是,我自然不能使用xs 来替换值:
>>> df.xs('init', 1, 1) = df.xs('init', 1, 1).round(decimals=3)
File "<ipython-input-12-47c16e5011a3>", line 1
df.xs('init', 1, 1) = df.xs('init', 1, 1).round(decimals=3)
SyntaxError: can't assign to function call
这里怎么走?
【问题讨论】:
标签: python pandas dataframe multi-index