I have two dataframes let's call them df1 and df2, which columns with slightly different headers which I need to compare. For example
df1 = pd.Dataframe('0001_baseline':[1,2,3], '0002_baseline':[1,2,3])
df1 = pd.Dataframe('0001_w2':[1,2,3], '0002_w2':[1,2,3])
I need to do the ratio of 0001_baseline/0001_w2. if the names were identical I would have
intersec = set(df1.columns).intersection(set(df2.columns))
and then do the ratio according to the intersections, but the column names are different. Is there a way to perform the intersection according to column name using regex? Or alternatively, knowing that I know how long are the characters, replace the names with a shorter version which won't cause a problem?
source https://stackoverflow.com/questions/72353661/comparing-pandas-dataframes-by-header-uring-regex
Comments
Post a Comment