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"]
. 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:
mask = df1[['Date','Day']].equals(df2[['Date','Day']])
If second df2 has only 2 columns:
mask = df1[['Date','Day']].equals(df2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.