0

I would like to merge/concat "outer" for 2 different dataframes with different set of holiday dates. Date column is string. Both dataframe prices exclude non-pricing days e.g. public holiday and weekends

Assuming Dataframe 1 follows US holiday:

df1_US_holiday

Date       Price_A
5/6/2020   2
5/5/2020   3
5/4/2020   4
5/1/2020   5
4/30/2020  6
4/29/2020  1
4/28/2020  3
4/27/2020  1

Assuming Dataframe 2 follows China holiday (note: 1-5 May is China holiday):

df2_China_holiday

Date       Price_B
5/6/2020   4
4/30/2020  3
4/29/2020  2
4/28/2020  2
4/27/2020  5

Expected merge/concat results:

Date       Price_A  Price_B
5/6/2020   2        4
5/5/2020   3        NaN
5/4/2020   4        NaN
5/1/2020   5        NaN
4/30/2020  6        3
4/29/2020  1        2
4/28/2020  3        2
4/27/2020  1        5

Ultimately, Would like fill the NaN for fillna(method='bfill'). Should I include any holiday library pack for this merge/concat action?

distalr
  • 29
  • 3
  • You can do it with [outer merge](https://stackoverflow.com/questions/53645882/pandas-merging-101), ``df1.merge(df2, on="Date", how="outer")`` – sushanth Jun 24 '20 at 12:54
  • i manage to solve it, as previously the above merge codes did not sort the dates, it just flush the `NaN` values down. I converted the date into `set_index` and `merged_df.sort_index(ascending=False,inplace=True)` – distalr Jun 24 '20 at 14:23

1 Answers1

0

Pandas provides various facilities for easily combining together Series or DataFrame with various kinds of set logic for the indexes and relational algebra functionality in the case of join / merge-type operations. Please take a look at these documents that may be useful for what you want to achieve