0

I have merged two dataframes (one between 1998 and 2014 and the other between 2008 and 2016). I want to plot the difference between two time series, one in the first dataframe and the other in the second dataframe. I tried to use this answer to a similar question. There is my code:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
result = pd.merge(data_df, etienne_df, left_index=True, right_index=True, how='outer')
Z = result['1M'] - result['NNGCS01']
mask = ((Z.index.values >= np.datetime64('2008-09-22')) - (Z.index.values <= np.datetime64('2014-02-25'))).any()
Z[mask].plot()
plt.show()

I got the following error:

Traceback (most recent call last):

File "regression.py", line 45, in

Z[mask].plot()

AttributeError: 'numpy.float64' object has no attribute 'plot'

How can I select the time range for my plot?

Community
  • 1
  • 1
Etienne
  • 108
  • 12
  • Do you have a typo on the mask line? Shouldn't the `-` be `&`? I also don't think you want the `any()` at the end. – JohnE Jan 05 '17 at 17:59
  • Well, it worked. Thanks. I tried to use [this](http://chrisalbon.com/python/pandas_selecting_rows_on_conditions.html) before but it failed. – Etienne Jan 06 '17 at 14:06

0 Answers0