How do I add a column from one DataFrame to another when both have index in different formats
I have a dataframe called df which looks like this:
and I have another dataframe called vix which looks like this:
previously I added the columns 'open ndaq' , 'open jpm' and 'open kya' like this:
df['open jpm'] = jpm_dataframe['open']
df['open ndaq'] = ndaq_dataframe['open']
df['open nya'] = nya_dataframe['open']
this worked since those dataframes had the exact same index as df (string date and time) however the vix dataframe has a date and time in a different format, how do I add the open column from vix to df such that it still corresponds to the same indices? i want the result to look like what I'd get if I could do
df['vix open'] = vix['open']
#(assuming vix and df somehow have the exact same index)
Solution 1:
You need DatetimeIndex
in both DataFrames:
vix.index = pd.to_datetime(vix.index, format='%m/%d/%Y')
df.index = pd.to_datetime(df.index)