python - pandas date_range, end karg -


Long time readers, first question, new for pandas, hope the question is understandable! I have a dataframe DF that is:

  in [151]: df.index out [151]: & lt; Class 'pandas.tseries.index.DatetimeIndex' & gt; [2013-08-04, ..., 2040-08-04] Length: 37, Freak: None, Timezone: Anyone  

I need a new data frame containing all values DF is already, and for all the quarterly dates, the NAN, which initiates the quarter after the first date in DF, and terminates the quarter after the last date in the DF.

My plan is:

<
  • In [163]: dfm = pd.DataFrame (index = pd.date_range (start = df.index [0], end = df.index [len (df) -1], freq = 'q')) In [164]: Dfs = pd.concat ([df, dfm]). [165]: dfs.tail () Out [165]: NPV 2040-03-31 Nain 2040-06-30 Nain 2040-07- 30 31977750.393512 2040-08-04 30000000.000000 2040-08-04 30000000.000000 [ 5 rows x 1 column]

    The issue is that the last quarter is 2040-06-30 and not 2040-09 -30. Then sets the queue before last keyword df.index [len (df) -1] in date_range , is a way to tell date ranges < / Code> to use quarterly?


  • Comments

    Popular posts from this blog

    import - Python ImportError: No module named wmi -

    Editing Python Class in Shell and SQLAlchemy -

    c# - MySQL Parameterized Select Query joining tables issue -