To merge on columns with different data types in pandas, we can convert one column to match the data type of the other column. In this case, we can convert the datetime64[ns]
column to object
using the astype()
method. Then, we can use pd.concat()
to join the two columns together. Here's an example:
main.py517 chars24 lines
Output:
main.py112 chars5 lines
Note that we converted the date
column to a string using the astype()
method before joining the two dataframes together. We then used pd.concat()
to join the two dataframes, setting the axis
parameter to 1
to join along the columns, and join
parameter to inner
to perform an inner join. Finally, we reset the index using reset_index()
to obtain the desired output.
gistlibby LogSnag