【发布时间】:2014-11-03 19:16:10
【问题描述】:
Dataframe 的每一列都需要根据该列中第一个元素的值对其值进行规范化。
for timestamp, prices in data.iteritems():
normalizedPrices = prices / prices[0]
print normalizedPrices # how do we update the DataFrame with this Series?
但是,一旦我们创建了规范化的数据列,我们如何更新 DataFrame?我相信如果我们这样做prices = normalizedPrices,我们只是在对 DataFrame 的副本/视图而不是原始 DataFrame 本身进行操作。
【问题讨论】:
-
旁注:根据@unutbu 的回答,最好的解决方案是循环遍历数据帧的行是非常罕见的
-
@PaulH 如我所见,代码循环遍历数据框的列(而不是行)。
标签: python python-2.7 pandas dataframe