Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

enter image description here

and I have another dataframe called vix which looks like this:enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

You need DatetimeIndex in both DataFrames:

vix.index = pd.to_datetime(vix.index, format='%m/%d/%Y')
df.index = pd.to_datetime(df.index)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading