我有一个多索引数据帧,如下所示:
ACA FP Equity UCG IM Equity
LAST PRICE VOLUME LAST PRICE VOLUME
date
2010-01-04 12.825 5879617.0 15.0292 10844639.0
2010-01-05 13.020 6928587.0 14.8092 16456228.0
2010-01-06 13.250 5290631.0 14.6834 10446450.0
2010-01-07 13.255 5328586.0 15.0292 31900341.0
2010-01-08 13.470 7160295.0 15.1707 40750768.0
如果我想为每个权益在dataframe中添加第三列,语法是什么?例如:
^{pr2}$但我想对每一个股票都这样做,而不是手动添加每一个。在
提前谢谢。在
如果需要所有
LAST PRICE
列乘以3
,请使用slicers选择它们并重命名列名:然后您需要^{} 输出:
^{pr2}${3{tuples}的另一个解决方案是从cd5}创建另一个
我能想到的最优雅的方式是:
apply语句允许您为dataframe中指定列的每个值执行一个给定函数,在本例中是一个将每个输入乘以3的lambda expression。运行apply语句将返回pandas Series,然后可以将其作为列添加到dataframe中。在
下面是一个简单的示例,演示如何使用简单的数据帧:
^{pr2}$相关问题 更多 >
编程相关推荐