[英]iterate through columns in 2 different excel sheets
I have an excel file with 2 tab sheets(A and B). 我有一个带有2个标签页(A和B)的Excel文件。 Each tab sheets has 10 columns corresponding to 10 different parameters. 每个选项卡都有10列,分别对应10个不同的参数。 I need iterate through both tab sheets and multiply column 1 in tab sheet A with column 1 in tab sheet B, multiply column 2 in tab sheet A to column 2 in tab sheet b, etc.. therefore I will obtain 10 columns corresponding to the 10 operations. 我需要遍历两个标签纸,然后将标签纸A的第1列与标签纸B的第1列相乘,将标签纸A的第2列乘以标签纸b的第2列,依此类推。因此,我将获得10列对应于10次操作。 How to I write that in Pandas? 我该怎么写在熊猫? Thanks in advance for your help 在此先感谢您的帮助
One of the comments had it pretty close. 评论之一非常接近。
dfs = pd.read_excel('test.xlsx', sheet_name = None, header=None)
dfs is now an ordered dictionary that looks like this: dfs现在是一个有序字典,如下所示:
OrderedDict([('a', 0 1 2
0 1 2 3
1 4 5 6), ('b', 0 1 2
0 7 8 9
1 10 11 12)])
You can get the multiplication like the comment suggests. 您可以按照注释建议获得乘法。
dfs['a'] * dfs['b']
Output: 输出:
0 1 2
0 7 16 27
1 40 55 72
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.