[英]How to compare columns in two dataframes in Python?
I have a problem where I want to check if first two columns of two dataframes are identical or not ?我有一个问题,我想检查两个数据帧的前两列是否相同? Let say I have
dataframe1
with columns ["Date","Day","Volume"]
and another dataframe2
with columns ["Date","Day"]
.让说,我有
dataframe1
与列["Date","Day","Volume"]
和另一dataframe2
与列["Date","Day"]
I want to check if these two data frames are having Date and Day in the same structure or not?我想检查这两个数据框是否具有相同结构的日期和日期? How can I achieve this in the most optimized way?
我怎样才能以最优化的方式实现这一目标?
If want compare exactly same values, same index and same length between 2 columns use DataFrame.equals
with subset of columns by list:如果要比较两列之间完全相同的值、相同的索引和相同的长度,请使用
DataFrame.equals
和列表中的DataFrame.equals
集:
mask = df1[['Date','Day']].equals(df2[['Date','Day']])
If second df2 has only 2 columns:如果第二个 df2 只有 2 列:
mask = df1[['Date','Day']].equals(df2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.