To create end of business month data frame from a stock data frame












0














I’m new to Python and Panda’s. I’m trying to figure out how to create a new data frame from a stock data frame that will contain only the rows for the day of the end of the business month.



Here is my Stock Data Frame:



apple = pd.read_csv("AppleStock.csv")
apple.head(10)

Date Open High Low Close Adj Close Volume
0 2013-02-28 63.435715 63.981430 63.057144 63.057144 47.371712 80628800

1 2013-03-01 62.571430 62.597141 61.425713 61.495716 46.198692 138112100

2 2013-03-04 61.114285 61.171429 59.857143 60.007141 45.080402 145688900

3 2013-03-05 60.211430 62.169998 60.107143 61.591427 46.270584 159608400

4 2013-03-06 62.072857 62.178570 60.632858 60.808571 45.682465 115062500

5 2013-03-07 60.642857 61.715714 60.151428 61.511429 46.210499 117118400

6 2013-03-08 61.400002 62.204285 61.230000 61.674286 46.332844 97870500

7 2013-03-11 61.392857 62.715714 60.734287 62.552856 46.992863 118559000

8 2013-03-12 62.228573 62.697144 61.081429 61.204285 45.979744 116477900

9 2013-03-13 61.207142 62.071430 60.765713 61.192856 45.971165 101387300


Here is my day of the end of the month array



month_index = pd.date_range('2013-02-28', '2018-02-28', freq='BM')

month_index
DatetimeIndex(['2013-02-28', '2013-03-29', '2013-04-30', '2013-05-31',
'2013-06-28', '2013-07-31', '2013-08-30', '2013-09-30',
'2013-10-31', '2013-11-29', '2013-12-31', '2014-01-31',
'2014-02-28', '2014-03-31', '2014-04-30', '2014-05-30',
'2014-06-30', '2014-07-31', '2014-08-29', '2014-09-30',
'2014-10-31', '2014-11-28', '2014-12-31', '2015-01-30',
'2015-02-27', '2015-03-31', '2015-04-30', '2015-05-29',
'2015-06-30', '2015-07-31', '2015-08-31', '2015-09-30',
'2015-10-30', '2015-11-30', '2015-12-31', '2016-01-29',
'2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31',
'2016-06-30', '2016-07-29', '2016-08-31', '2016-09-30',
'2016-10-31', '2016-11-30', '2016-12-30', '2017-01-31',
'2017-02-28', '2017-03-31', '2017-04-28', '2017-05-31',
'2017-06-30', '2017-07-31', '2017-08-31', '2017-09-29',
'2017-10-31', '2017-11-30', '2017-12-29', '2018-01-31',
'2018-02-28'],
dtype='datetime64[ns]', freq=‘BM')


How do I create the new data frame just containing the rows of the business day of the end of the month?










share|improve this question





























    0














    I’m new to Python and Panda’s. I’m trying to figure out how to create a new data frame from a stock data frame that will contain only the rows for the day of the end of the business month.



    Here is my Stock Data Frame:



    apple = pd.read_csv("AppleStock.csv")
    apple.head(10)

    Date Open High Low Close Adj Close Volume
    0 2013-02-28 63.435715 63.981430 63.057144 63.057144 47.371712 80628800

    1 2013-03-01 62.571430 62.597141 61.425713 61.495716 46.198692 138112100

    2 2013-03-04 61.114285 61.171429 59.857143 60.007141 45.080402 145688900

    3 2013-03-05 60.211430 62.169998 60.107143 61.591427 46.270584 159608400

    4 2013-03-06 62.072857 62.178570 60.632858 60.808571 45.682465 115062500

    5 2013-03-07 60.642857 61.715714 60.151428 61.511429 46.210499 117118400

    6 2013-03-08 61.400002 62.204285 61.230000 61.674286 46.332844 97870500

    7 2013-03-11 61.392857 62.715714 60.734287 62.552856 46.992863 118559000

    8 2013-03-12 62.228573 62.697144 61.081429 61.204285 45.979744 116477900

    9 2013-03-13 61.207142 62.071430 60.765713 61.192856 45.971165 101387300


    Here is my day of the end of the month array



    month_index = pd.date_range('2013-02-28', '2018-02-28', freq='BM')

    month_index
    DatetimeIndex(['2013-02-28', '2013-03-29', '2013-04-30', '2013-05-31',
    '2013-06-28', '2013-07-31', '2013-08-30', '2013-09-30',
    '2013-10-31', '2013-11-29', '2013-12-31', '2014-01-31',
    '2014-02-28', '2014-03-31', '2014-04-30', '2014-05-30',
    '2014-06-30', '2014-07-31', '2014-08-29', '2014-09-30',
    '2014-10-31', '2014-11-28', '2014-12-31', '2015-01-30',
    '2015-02-27', '2015-03-31', '2015-04-30', '2015-05-29',
    '2015-06-30', '2015-07-31', '2015-08-31', '2015-09-30',
    '2015-10-30', '2015-11-30', '2015-12-31', '2016-01-29',
    '2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31',
    '2016-06-30', '2016-07-29', '2016-08-31', '2016-09-30',
    '2016-10-31', '2016-11-30', '2016-12-30', '2017-01-31',
    '2017-02-28', '2017-03-31', '2017-04-28', '2017-05-31',
    '2017-06-30', '2017-07-31', '2017-08-31', '2017-09-29',
    '2017-10-31', '2017-11-30', '2017-12-29', '2018-01-31',
    '2018-02-28'],
    dtype='datetime64[ns]', freq=‘BM')


    How do I create the new data frame just containing the rows of the business day of the end of the month?










    share|improve this question



























      0












      0








      0







      I’m new to Python and Panda’s. I’m trying to figure out how to create a new data frame from a stock data frame that will contain only the rows for the day of the end of the business month.



      Here is my Stock Data Frame:



      apple = pd.read_csv("AppleStock.csv")
      apple.head(10)

      Date Open High Low Close Adj Close Volume
      0 2013-02-28 63.435715 63.981430 63.057144 63.057144 47.371712 80628800

      1 2013-03-01 62.571430 62.597141 61.425713 61.495716 46.198692 138112100

      2 2013-03-04 61.114285 61.171429 59.857143 60.007141 45.080402 145688900

      3 2013-03-05 60.211430 62.169998 60.107143 61.591427 46.270584 159608400

      4 2013-03-06 62.072857 62.178570 60.632858 60.808571 45.682465 115062500

      5 2013-03-07 60.642857 61.715714 60.151428 61.511429 46.210499 117118400

      6 2013-03-08 61.400002 62.204285 61.230000 61.674286 46.332844 97870500

      7 2013-03-11 61.392857 62.715714 60.734287 62.552856 46.992863 118559000

      8 2013-03-12 62.228573 62.697144 61.081429 61.204285 45.979744 116477900

      9 2013-03-13 61.207142 62.071430 60.765713 61.192856 45.971165 101387300


      Here is my day of the end of the month array



      month_index = pd.date_range('2013-02-28', '2018-02-28', freq='BM')

      month_index
      DatetimeIndex(['2013-02-28', '2013-03-29', '2013-04-30', '2013-05-31',
      '2013-06-28', '2013-07-31', '2013-08-30', '2013-09-30',
      '2013-10-31', '2013-11-29', '2013-12-31', '2014-01-31',
      '2014-02-28', '2014-03-31', '2014-04-30', '2014-05-30',
      '2014-06-30', '2014-07-31', '2014-08-29', '2014-09-30',
      '2014-10-31', '2014-11-28', '2014-12-31', '2015-01-30',
      '2015-02-27', '2015-03-31', '2015-04-30', '2015-05-29',
      '2015-06-30', '2015-07-31', '2015-08-31', '2015-09-30',
      '2015-10-30', '2015-11-30', '2015-12-31', '2016-01-29',
      '2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31',
      '2016-06-30', '2016-07-29', '2016-08-31', '2016-09-30',
      '2016-10-31', '2016-11-30', '2016-12-30', '2017-01-31',
      '2017-02-28', '2017-03-31', '2017-04-28', '2017-05-31',
      '2017-06-30', '2017-07-31', '2017-08-31', '2017-09-29',
      '2017-10-31', '2017-11-30', '2017-12-29', '2018-01-31',
      '2018-02-28'],
      dtype='datetime64[ns]', freq=‘BM')


      How do I create the new data frame just containing the rows of the business day of the end of the month?










      share|improve this question















      I’m new to Python and Panda’s. I’m trying to figure out how to create a new data frame from a stock data frame that will contain only the rows for the day of the end of the business month.



      Here is my Stock Data Frame:



      apple = pd.read_csv("AppleStock.csv")
      apple.head(10)

      Date Open High Low Close Adj Close Volume
      0 2013-02-28 63.435715 63.981430 63.057144 63.057144 47.371712 80628800

      1 2013-03-01 62.571430 62.597141 61.425713 61.495716 46.198692 138112100

      2 2013-03-04 61.114285 61.171429 59.857143 60.007141 45.080402 145688900

      3 2013-03-05 60.211430 62.169998 60.107143 61.591427 46.270584 159608400

      4 2013-03-06 62.072857 62.178570 60.632858 60.808571 45.682465 115062500

      5 2013-03-07 60.642857 61.715714 60.151428 61.511429 46.210499 117118400

      6 2013-03-08 61.400002 62.204285 61.230000 61.674286 46.332844 97870500

      7 2013-03-11 61.392857 62.715714 60.734287 62.552856 46.992863 118559000

      8 2013-03-12 62.228573 62.697144 61.081429 61.204285 45.979744 116477900

      9 2013-03-13 61.207142 62.071430 60.765713 61.192856 45.971165 101387300


      Here is my day of the end of the month array



      month_index = pd.date_range('2013-02-28', '2018-02-28', freq='BM')

      month_index
      DatetimeIndex(['2013-02-28', '2013-03-29', '2013-04-30', '2013-05-31',
      '2013-06-28', '2013-07-31', '2013-08-30', '2013-09-30',
      '2013-10-31', '2013-11-29', '2013-12-31', '2014-01-31',
      '2014-02-28', '2014-03-31', '2014-04-30', '2014-05-30',
      '2014-06-30', '2014-07-31', '2014-08-29', '2014-09-30',
      '2014-10-31', '2014-11-28', '2014-12-31', '2015-01-30',
      '2015-02-27', '2015-03-31', '2015-04-30', '2015-05-29',
      '2015-06-30', '2015-07-31', '2015-08-31', '2015-09-30',
      '2015-10-30', '2015-11-30', '2015-12-31', '2016-01-29',
      '2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31',
      '2016-06-30', '2016-07-29', '2016-08-31', '2016-09-30',
      '2016-10-31', '2016-11-30', '2016-12-30', '2017-01-31',
      '2017-02-28', '2017-03-31', '2017-04-28', '2017-05-31',
      '2017-06-30', '2017-07-31', '2017-08-31', '2017-09-29',
      '2017-10-31', '2017-11-30', '2017-12-29', '2018-01-31',
      '2018-02-28'],
      dtype='datetime64[ns]', freq=‘BM')


      How do I create the new data frame just containing the rows of the business day of the end of the month?







      python pandas






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 14:55









      yatu

      5,1961423




      5,1961423










      asked Nov 19 '18 at 14:44









      J Ski

      32




      32
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Convert the dates in your dataframe to datetime.



          apple.index = pd.to_datetime(apple['Date'])


          Use your month_index to get desired rows.



          apple_month = apple.loc[month_index]





          share|improve this answer



















          • 1




            The .ix indexer is deprecated starting in version 0.20.0,
            – yatu
            Nov 19 '18 at 14:55






          • 1




            Good to know thanks! I modified my answer
            – onno
            Nov 19 '18 at 15:00










          • Thanks onno for the answer.
            – J Ski
            Nov 19 '18 at 22:32












          • Glad to help. If it works for you, please upvote my answer and mark as accepted.
            – onno
            Nov 20 '18 at 16:30



















          0














          If I understood correctly, this will do:



          apple[apple['Open'].isin(month_index)]

          Date Open High Low Close Adj Close.1
          0 0 2013-02-28 63.435715 63.98143 63.057144 63.057144 47.371712

          Volume
          0 80628800





          share|improve this answer





















          • Thanks Alexandre
            – J Ski
            Nov 19 '18 at 22:33










          • YW :) Remember to accept if it helped
            – yatu
            Dec 28 '18 at 8:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377024%2fto-create-end-of-business-month-data-frame-from-a-stock-data-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Convert the dates in your dataframe to datetime.



          apple.index = pd.to_datetime(apple['Date'])


          Use your month_index to get desired rows.



          apple_month = apple.loc[month_index]





          share|improve this answer



















          • 1




            The .ix indexer is deprecated starting in version 0.20.0,
            – yatu
            Nov 19 '18 at 14:55






          • 1




            Good to know thanks! I modified my answer
            – onno
            Nov 19 '18 at 15:00










          • Thanks onno for the answer.
            – J Ski
            Nov 19 '18 at 22:32












          • Glad to help. If it works for you, please upvote my answer and mark as accepted.
            – onno
            Nov 20 '18 at 16:30
















          0














          Convert the dates in your dataframe to datetime.



          apple.index = pd.to_datetime(apple['Date'])


          Use your month_index to get desired rows.



          apple_month = apple.loc[month_index]





          share|improve this answer



















          • 1




            The .ix indexer is deprecated starting in version 0.20.0,
            – yatu
            Nov 19 '18 at 14:55






          • 1




            Good to know thanks! I modified my answer
            – onno
            Nov 19 '18 at 15:00










          • Thanks onno for the answer.
            – J Ski
            Nov 19 '18 at 22:32












          • Glad to help. If it works for you, please upvote my answer and mark as accepted.
            – onno
            Nov 20 '18 at 16:30














          0












          0








          0






          Convert the dates in your dataframe to datetime.



          apple.index = pd.to_datetime(apple['Date'])


          Use your month_index to get desired rows.



          apple_month = apple.loc[month_index]





          share|improve this answer














          Convert the dates in your dataframe to datetime.



          apple.index = pd.to_datetime(apple['Date'])


          Use your month_index to get desired rows.



          apple_month = apple.loc[month_index]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 15:00

























          answered Nov 19 '18 at 14:53









          onno

          51427




          51427








          • 1




            The .ix indexer is deprecated starting in version 0.20.0,
            – yatu
            Nov 19 '18 at 14:55






          • 1




            Good to know thanks! I modified my answer
            – onno
            Nov 19 '18 at 15:00










          • Thanks onno for the answer.
            – J Ski
            Nov 19 '18 at 22:32












          • Glad to help. If it works for you, please upvote my answer and mark as accepted.
            – onno
            Nov 20 '18 at 16:30














          • 1




            The .ix indexer is deprecated starting in version 0.20.0,
            – yatu
            Nov 19 '18 at 14:55






          • 1




            Good to know thanks! I modified my answer
            – onno
            Nov 19 '18 at 15:00










          • Thanks onno for the answer.
            – J Ski
            Nov 19 '18 at 22:32












          • Glad to help. If it works for you, please upvote my answer and mark as accepted.
            – onno
            Nov 20 '18 at 16:30








          1




          1




          The .ix indexer is deprecated starting in version 0.20.0,
          – yatu
          Nov 19 '18 at 14:55




          The .ix indexer is deprecated starting in version 0.20.0,
          – yatu
          Nov 19 '18 at 14:55




          1




          1




          Good to know thanks! I modified my answer
          – onno
          Nov 19 '18 at 15:00




          Good to know thanks! I modified my answer
          – onno
          Nov 19 '18 at 15:00












          Thanks onno for the answer.
          – J Ski
          Nov 19 '18 at 22:32






          Thanks onno for the answer.
          – J Ski
          Nov 19 '18 at 22:32














          Glad to help. If it works for you, please upvote my answer and mark as accepted.
          – onno
          Nov 20 '18 at 16:30




          Glad to help. If it works for you, please upvote my answer and mark as accepted.
          – onno
          Nov 20 '18 at 16:30













          0














          If I understood correctly, this will do:



          apple[apple['Open'].isin(month_index)]

          Date Open High Low Close Adj Close.1
          0 0 2013-02-28 63.435715 63.98143 63.057144 63.057144 47.371712

          Volume
          0 80628800





          share|improve this answer





















          • Thanks Alexandre
            – J Ski
            Nov 19 '18 at 22:33










          • YW :) Remember to accept if it helped
            – yatu
            Dec 28 '18 at 8:46
















          0














          If I understood correctly, this will do:



          apple[apple['Open'].isin(month_index)]

          Date Open High Low Close Adj Close.1
          0 0 2013-02-28 63.435715 63.98143 63.057144 63.057144 47.371712

          Volume
          0 80628800





          share|improve this answer





















          • Thanks Alexandre
            – J Ski
            Nov 19 '18 at 22:33










          • YW :) Remember to accept if it helped
            – yatu
            Dec 28 '18 at 8:46














          0












          0








          0






          If I understood correctly, this will do:



          apple[apple['Open'].isin(month_index)]

          Date Open High Low Close Adj Close.1
          0 0 2013-02-28 63.435715 63.98143 63.057144 63.057144 47.371712

          Volume
          0 80628800





          share|improve this answer












          If I understood correctly, this will do:



          apple[apple['Open'].isin(month_index)]

          Date Open High Low Close Adj Close.1
          0 0 2013-02-28 63.435715 63.98143 63.057144 63.057144 47.371712

          Volume
          0 80628800






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 14:50









          yatu

          5,1961423




          5,1961423












          • Thanks Alexandre
            – J Ski
            Nov 19 '18 at 22:33










          • YW :) Remember to accept if it helped
            – yatu
            Dec 28 '18 at 8:46


















          • Thanks Alexandre
            – J Ski
            Nov 19 '18 at 22:33










          • YW :) Remember to accept if it helped
            – yatu
            Dec 28 '18 at 8:46
















          Thanks Alexandre
          – J Ski
          Nov 19 '18 at 22:33




          Thanks Alexandre
          – J Ski
          Nov 19 '18 at 22:33












          YW :) Remember to accept if it helped
          – yatu
          Dec 28 '18 at 8:46




          YW :) Remember to accept if it helped
          – yatu
          Dec 28 '18 at 8:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377024%2fto-create-end-of-business-month-data-frame-from-a-stock-data-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith