【问题标题】:importing 2 Excel sheet and comparing their dataframe for computation and ploting graph导入 2 个 Excel 工作表并比较它们的数据框以进行计算和绘图
【发布时间】:2016-04-02 09:45:55
【问题描述】:

使用python 3.5 pandas 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)中的数据进行比较。

现在的问题是如何将参考文件的第一行(仅单行)与数据文件的多行进行比较,基本上数据文件中的值应该小于或等于参考文件的值?

找到DATA文件df of Data file with name stu的截图

与数据进行比较的参考文件df of Reference_File with name paper

也不想合并2个df。

【问题讨论】:

    标签: python excel python-3.x pandas


    【解决方案1】:

    你可以这样做:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多