python:在另一个数据框中的所有行中的所有行中的所有行中的行
我有两个数据框,如下所示:
df1:
A B C D
index
0 10000 20000 30000 40000
df2:
time type A B C D
index
0 5/2020 unit 1000 4000 900 200
1 6/2020 unit 7000 2000 600 4000
我想将df1.iloc [0]
划分为DF2中的所有行以获取以下内容:
df:
time type A B C D
index
0 5/2020 unit 10 5 33.33 200
1 6/2020 unit 1.43 10 50 10
我尝试使用df1.iloc [0] .div(div( df2.iloc [:])
,但这为我提供了除0索引以外的所有行。 任何建议将不胜感激。谢谢。
I have two DataFrames as follows:
df1:
A B C D
index
0 10000 20000 30000 40000
df2:
time type A B C D
index
0 5/2020 unit 1000 4000 900 200
1 6/2020 unit 7000 2000 600 4000
I want to divide df1.iloc[0]
by all rows in df2 to get the following:
df:
time type A B C D
index
0 5/2020 unit 10 5 33.33 200
1 6/2020 unit 1.43 10 50 10
I tried to use df1.iloc[0].div(df2.iloc[:])
but that gave me NaNs for all rows other than the 0 index.
Any suggestions would be greatly appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让我们做
Let us do
另一种方法,使用numpy Divide
another way to do it, using numpy divide
您可以使用 >。
打印(DF):
You can use
div
.print(df):