kjanko kjanko - 7 months ago 46
Python Question

Pandas merge does not work

enter image description here

I have the following 2 dataframes, and I wish to join them on the Date column.

When I try to do:

final_df = pd.merge(event_by_codes, stock_norm)

I get No common columns to perform merge on.
(The date is timestamp object)

Any idea what is going on?

Answer Source
  • Date is not a column... Its an index
  • merge merges on columns... you want join which operates on indices
  • make sure your indices are actually datetime and not strings

stock_norm.index = pd.to_datetime(stock_norm.index)
event_by_codes.index = pd.to_datetime(event_by_codes.index)