简体   繁体   English

如何比较2个DataFrame中Python中不同的列名(列按相同顺序排列)

[英]How to Compare 2 DataFrame which different Column Names( Columns are in same Sequence) in Python

The requirement is to compare 2 dataframe(dataset) both having different header. 要求是比较两个具有不同头的数据帧(数据集)。 Basically I am querying database(HANA) table and comparing its output with the output of a SQL code as data testing 基本上我正在查询数据库(HANA)表并将其输出与SQL代码的输出进行比较以进行数据测试

Ex 防爆

df1: df1:

customerNo  City   Amount
C1          ABC     100
C2          XYZ     50

df2: df2:

customer   Place   Amount
C1          ABC     100
C2          PQR     40

Although column names are different but they are in the correct order. 尽管列名不同,但是它们的顺序正确。 Is there a way to compare dataset just based on column orders? 有没有一种方法可以仅基于列顺序比较数据集?

I tried datacompy.Compare(df1,df2, on_index=True) but its not working. 我尝试了datacompy.Compare(df1,df2, on_index=True)但它不起作用。

Try renaming the columns and then running your compare tests. 尝试重命名列,然后运行比较测试。 An example for renaming columns: 重命名列的示例:

df2 = df2.rename(columns = {'customer':'customerNo','Place':'city','Amount':'Amount'})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 比较相同 dataframe 的两列并返回相同 dataframe 的不同列 - Compare two columns of the same dataframe and returns a different column of the same dataframe 如何比较Python中相同DataFrame的不同行 - How to compare different rows of the same DataFrame in Python Python>Pandas>对具有相同列名、相同索引值但索引长度不同的不同数据框中的列求和 - Python>Pandas>Summing columns in different data frames which have same column names, same index values but not same same length of index 比较同一行但不同列中的字​​符串并捕获它们在哪一列中不相等 - compare strings in the same row but in different columns and catch in which column they are not equal 如何将同一列中以相似名称结尾的不同行中的列附加 - How to append the columns in the same column in different rows which endswith similar names 如何比较不同列中的同一行与python? - How to compare same row in different column with python? 如何遍历以整数作为列名的 dataframe 的列 - how to loop through columns of a dataframe which have intezers as column names 如何比较和匹配来自同一 dataframe 不同列的数据 - How to compare and match data from different columns of same dataframe 如何重命名具有相同列名的 dataframe 的列? - How to rename columns of dataframe that has same column names? 如何在 python dataframe 的同一列中连接相同的行名 - how to concatenate same row names in same column on python dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM