导入2张Excel表格并比较它们的数据框进行计算和绘图

2024-04-25 03:33:37 发布

您现在位置:Python中文网/ 问答频道 /正文

使用python 3.5.0.18

import pandas as pd

导入了2个单独的excel文件,这里1)stu = pd.read_excel("D:\\program\\python\\sample_data\\name1.xlsx",index_col=2)是数据文件,其他2)paper = pd.read_excel("D:\\program\\python\\sample_data\\name2.xlsx")是参考文件,与第一个文件(名称stu)中的数据进行比较。你知道吗

现在的问题是如何比较参考文件的第一行(仅一行)和数据文件的多行基本上数据文件中的值应该小于或等于参考文件的值??你知道吗

查找数据文件df of Data file with name stu的屏幕截图

要与之比较数据的引用文件df of Reference_File with name paper

也不想合并2个df。你知道吗


Tags: 文件of数据sampledfreaddata数据文件
1条回答
网友
1楼 · 发布于 2024-04-25 03:33:37

你可以这样做:

In [116]: df
Out[116]:
   Q1.1  Q1.2  Q1.3  Q1.4  Q1.5  Q1.6
0     1     0     1     0     1     0
1     0     1     0     1     0     1
2     1     1     1     1     1     1
3     0     0     0     0     0     0
4     1     0     1     0     1     0
5     0     0     0     0     0     0

In [117]: ref
Out[117]:
   Q1.1  Q1.2  Q1.3  Q1.4  Q1.5  Q1.6
0     0     0     0     0     0     0

In [118]: df[df.apply(lambda row: (row == ref).all(), axis=1).all(axis=1)]
Out[118]:
   Q1.1  Q1.2  Q1.3  Q1.4  Q1.5  Q1.6
3     0     0     0     0     0     0
5     0     0     0     0     0     0

相关问题 更多 >