数据帧中的乘法

时间:2019-03-20 19:23:03

标签: python python-3.x python-2.7 python-requests

我有这两个熊猫数据帧,我想将第一行与Log_Return数据帧的整个第一列相乘,类似地,将第一数据帧的第二行与Log_Returns的第二列相乘,依此类推。请借助循环帮助我解决此问题。

enter image description here

1 个答案:

答案 0 :(得分:0)

此代码可以为您提供帮助:

i=0
    for j in range(Log_return.shape[1]):
#j chooses the column of Log dataframe
#shape[1] gives number of columns
        for k in range(len(Log_return)):
# k chooses the rows one by one of jth column

             shares.iloc[i,0]*Log_return.iloc[k,j]
#you can multiply and even store the values or do any operations you want 
        i+=1
#i determines the row of shares dataframe