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

      8,2011926




      8,2011926










      asked Nov 19 '18 at 14:44









      J SkiJ Ski

      32




      32
























          1 Answer
          1






          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











          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          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









          onnoonno

          52927




          52927








          • 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


















          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.




          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

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?