0

I plotted a data frame like this:

           Date  Quote-Spread
  0   2013-11-17           2.0
  1   2013-12-10           8.0
  2   2013-12-11           8.0
  3   2014-06-01           5.0
  4   2014-06-23          15.0
  5   2014-06-24          45.0
  6   2014-06-25          10.0
  7   2014-06-28          20.0
  8   2014-09-13       50000.0
  9   2015-03-30      250000.0
  10  2016-04-02      103780.0
  11  2016-04-03      119991.0
  12  2016-04-04       29994.0
  13  2016-04-05       69993.0
  14  2016-04-06       39997.0
  15  2016-04-09      490321.0
  16  2016-04-10       65485.0
  17  2016-04-11      141470.0
  18  2016-04-12      109939.0
  19  2016-04-13       29983.0
  20  2016-04-16       39964.0
  21  2016-04-17       39964.0
  22  2016-04-18       79920.0
  23  2016-04-19       29997.0
  24  2016-04-20      108414.0
  25  2016-04-23      126849.0
  26  2016-04-24      206853.0
  27  2016-04-25       37559.0
  28  2016-04-26       22817.0
  29  2016-04-27       37506.0
  30  2016-04-30       37597.0
  31  2016-05-01       18799.0
  32  2016-05-02       18799.0
  33  2016-05-03        9400.0
  34  2016-05-07       29890.0
  35  2016-05-08       29193.0
  36  2016-05-09        7792.0
  37  2016-05-10        3199.0
  38  2016-05-11        8538.0
  39  2016-05-14       49937.0

I use this command to plot them in ipython:

  df2.plot(x= 'Date', y='Quote-Spread')

  plt.show()

But my figure is plotted like this:

enter image description here

As you can see in day 2014-04-23, the Quote-Spread has a value about 126,000. But in plot it is just zero.

my whole plot is like this:

enter image description here

Here is my code of original data:

  Sachad = df.loc[df['SID']== 40065016131938148]
  #Drop rows with any zero
  df1 = df1[~(df1 == 0).any(axis = 1)]
  df1['Quote-Spread'] = (df1['SellPrice'].mask(df1['SellPrice'].eq(0))-
  df1['BuyPrice'].mask(df1['BuyPrice'].eq(0))).abs()
  df2 = df1.groupby('Date' , as_index = False )['Quote-Spread'].mean()
  df2.plot(x= 'Date', y='Quote-Spread')
  plt.show()

Another question is how i can plot for specific dates like between 2014-04-01 up to 2016-06-01. and draw vertical red lines for dates 2014-06-06 and 2016-01-06?

ary
  • 151
  • 1
  • 2
  • 14

1 Answers1

1

Please provide the code that produced the working plot. Any warning messages?

As for your last questions: to select the rows you want, you can simply use > and < operators to compare two datetimes in conditional statements.

For vertical lines, you can use plt.axvline(x=date, color = 'r')

leerssej
  • 14,260
  • 6
  • 48
  • 57
stevebroll
  • 175
  • 1
  • 8
  • 1
    I edited my question, if it is necessary i provide a sample of my original data. sorry but i could not understand how to use" >and< ". if it is possible use an example or give me a link.thank you – ary Nov 17 '17 at 20:04
  • See the following link to answer your question, it explains better than I could here. https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas – stevebroll Nov 17 '17 at 20:16