【问题标题】:multiplication in dataframe数据框中的乘法
【发布时间】:2019-03-20 19:23:03
【问题描述】:

我有这两个 pandas 数据帧,我想将第一行乘以与 Log_Return 数据帧的整个第一列共享,类似地,第一个数据帧的第二行与 Log_Returns 的第二列等等。请帮助我在循环的帮助下解决这个问题。

【问题讨论】:

  • 你应该把代码贴在这里。
  • 我只是想知道我该怎么做
  • 请在创建minimal reproducible example时查看此链接
  • @HussnainAkbar 这与requests 有什么关系?你用那个标记了这个问题......

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


【解决方案1】:

这段代码可以帮助你:

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

【讨论】:

  • 我已经尝试过这段代码,但出现错误但没有输出。请帮帮我,我被困在这里 IndexError: single positional indexer is out-of-bounds
猜你喜欢
  • 2012-09-03
  • 1970-01-01
  • 2017-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多