我有以下DataFrame
AAPL F IBM
Date
2016-05-02 46.536664 13.62 143.881476
2016-05-03 47.302004 13.43 142.752373
2016-05-04 46.810001 13.31 142.871221
2016-05-05 46.619999 13.32 145.070003
2016-05-06 46.360000 13.44 147.289993
我想将每一列除以第一行的值并乘以100.计算后,前两行应如下所示:
AAPL F IBM
Date
2016-05-02 100 100 100
2016-05-03 101.63 98.60 99.21
我在挣扎,但我无法得到它。任何帮助表示赞赏
答案 0 :(得分:4)
尝试这样的事情:
char[] array = new char[0];
assert array != null;
assert array.length == 0;
assert "".equals(new String(array));
或
df /= df.iloc[0]/100
测试:
df = df.apply(lambda x: x/x.iloc[0]*100)
输出:
In [51]: df
Out[51]:
AAPL F IBM
Date
2016-05-02 46.536664 13.62 143.881476
2016-05-03 47.302004 13.43 142.752373
2016-05-04 46.810001 13.31 142.871221
2016-05-05 46.619999 13.32 145.070003
2016-05-06 46.360000 13.44 147.289993