I have two series objects (XVar and YVar) with different indices.
I want to create a dataframe with the intersection of both series objects based on the index of XVar
YVar
Name
1995-03 0.042365
1995-04 0.048894
1995-05 0.016465
1995-06 0.041724
1995-07 0.009067
1995-08 -0.018166
1995-09 -0.026390
1995-10 0.022338
1995-11 0.037427
1995-12 0.071605
...
Name: YVar, dtype: float64
XVar
Name
1995-02 84.9
1995-05 85.2
1995-08 84.1
1995-11 83.7
...
Name: XVar, dtype: float64
Desired output should look like this
XVar YVar
1995-05 85.2 0.016465
1995-08 84.1 -0.018166
1995-11 83.7 0.037427
...
I tried to do it using pd.concat. However, the output only contains XVar...
XVar_YVar = pd.concat([XVar, YVar], join = 'inner')
What am I missing here?
Best rentec
join
would be a better choice here:
pd.DataFrame(XVar).join(pd.DataFrame(YVar), how='inner')
should give the expected result;