0

The index is a timestamp and column name, and also the ability to replace NaN to value. It does not seem to be working.

sample:

import pandas as pd

times = pd.to_datetime(pd.Series(['2014-07-4',
'2014-07-15','2014-08-24','2014-08-25','2014-09-10','2014-09-17']))
valuea = [0.01, 0.02, -0.03, 0.4 ,0.5,np.NaN]

times2 = pd.to_datetime(pd.Series(['2014-07-6',
'2014-07-16','2014-08-27','2014-09-5','2014-09-11','2014-09-17']))
valuea2 = [1, 2, 3, 4,5,-6]


df1 = pd.DataFrame({'value A': valuea}, index=times)
df2 = pd.DataFrame({'value A': valuea2}, index=times2)

df3=pd.merge(df1,df2, left_index=True, right_index=True)
df3.head()
3
  • Do you get any error(s)? Try replacing np.Nan to np.NaN Commented Jun 12, 2018 at 19:42
  • sorry mistype... Commented Jun 12, 2018 at 19:56
  • May be you need pd.concat([df1, df2]) ? Commented Jun 12, 2018 at 20:02

1 Answer 1

1

Assuming you need outer join

pd.concat([df1,df2],axis=1)
Out[321]: 
            value A  value A
2014-07-04     0.01      NaN
2014-07-06      NaN      1.0
2014-07-15     0.02      NaN
2014-07-16      NaN      2.0
2014-08-24    -0.03      NaN
2014-08-25     0.40      NaN
2014-08-27      NaN      3.0
2014-09-05      NaN      4.0
2014-09-10     0.50      NaN
2014-09-11      NaN      5.0
2014-09-17      NaN     -6.0

Update

df1.combine_first(df2)
Out[324]: 
            value A
2014-07-04     0.01
2014-07-06     1.00
2014-07-15     0.02
2014-07-16     2.00
2014-08-24    -0.03
2014-08-25     0.40
2014-08-27     3.00
2014-09-05     4.00
2014-09-10     0.50
2014-09-11     5.00
2014-09-17    -6.00
Sign up to request clarification or add additional context in comments.

3 Comments

pd.concat([df1, df2]) would do.
@RamiRamich that is combine_first
@Wen, I am not sure if I understand OP's question fully but yes, you are right. pd.concat([df1, df2]).dropna() 's equivavelnt would be df1.combine_first(df2). After all OP did mention about NaN values. It is not clear if OP wants to remove it or keep it and then use .fillna()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.