Filtering Pandas column with specific conditions?












0















I have a pandas dataframe that looks like



                 Start Time
0 2017-06-23 15:09:32
1 2017-05-25 18:19:03
2 2017-01-04 08:27:49
3 2017-03-06 13:49:38
4 2017-01-17 14:53:07
5 2017-06-26 09:01:20
6 2017-05-26 09:41:44
7 2017-01-21 14:28:38
8 2017-04-20 16:08:51


I want to filter out the ones with month == 06. So it would be the row 1 and 5.
I know how to filter it out for column that has only few categories, but in this case, if it's a date, I need to parse the date and check the month. But I am not sure how to do it with pandas. Please help.










share|improve this question



























    0















    I have a pandas dataframe that looks like



                     Start Time
    0 2017-06-23 15:09:32
    1 2017-05-25 18:19:03
    2 2017-01-04 08:27:49
    3 2017-03-06 13:49:38
    4 2017-01-17 14:53:07
    5 2017-06-26 09:01:20
    6 2017-05-26 09:41:44
    7 2017-01-21 14:28:38
    8 2017-04-20 16:08:51


    I want to filter out the ones with month == 06. So it would be the row 1 and 5.
    I know how to filter it out for column that has only few categories, but in this case, if it's a date, I need to parse the date and check the month. But I am not sure how to do it with pandas. Please help.










    share|improve this question

























      0












      0








      0








      I have a pandas dataframe that looks like



                       Start Time
      0 2017-06-23 15:09:32
      1 2017-05-25 18:19:03
      2 2017-01-04 08:27:49
      3 2017-03-06 13:49:38
      4 2017-01-17 14:53:07
      5 2017-06-26 09:01:20
      6 2017-05-26 09:41:44
      7 2017-01-21 14:28:38
      8 2017-04-20 16:08:51


      I want to filter out the ones with month == 06. So it would be the row 1 and 5.
      I know how to filter it out for column that has only few categories, but in this case, if it's a date, I need to parse the date and check the month. But I am not sure how to do it with pandas. Please help.










      share|improve this question














      I have a pandas dataframe that looks like



                       Start Time
      0 2017-06-23 15:09:32
      1 2017-05-25 18:19:03
      2 2017-01-04 08:27:49
      3 2017-03-06 13:49:38
      4 2017-01-17 14:53:07
      5 2017-06-26 09:01:20
      6 2017-05-26 09:41:44
      7 2017-01-21 14:28:38
      8 2017-04-20 16:08:51


      I want to filter out the ones with month == 06. So it would be the row 1 and 5.
      I know how to filter it out for column that has only few categories, but in this case, if it's a date, I need to parse the date and check the month. But I am not sure how to do it with pandas. Please help.







      pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 2:32









      Dawn17Dawn17

      833417




      833417
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Using



          #df['Start Time']=pd.to_datetime(df['Start Time'])
          df1=df[df['Start Time'].dt.month==6].copy()





          share|improve this answer
























          • Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

            – Dawn17
            Nov 15 '18 at 2:38











          • @Dawn17 try run my marked line

            – Wen-Ben
            Nov 15 '18 at 2:42











          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%2f53311599%2ffiltering-pandas-column-with-specific-conditions%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









          2














          Using



          #df['Start Time']=pd.to_datetime(df['Start Time'])
          df1=df[df['Start Time'].dt.month==6].copy()





          share|improve this answer
























          • Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

            – Dawn17
            Nov 15 '18 at 2:38











          • @Dawn17 try run my marked line

            – Wen-Ben
            Nov 15 '18 at 2:42
















          2














          Using



          #df['Start Time']=pd.to_datetime(df['Start Time'])
          df1=df[df['Start Time'].dt.month==6].copy()





          share|improve this answer
























          • Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

            – Dawn17
            Nov 15 '18 at 2:38











          • @Dawn17 try run my marked line

            – Wen-Ben
            Nov 15 '18 at 2:42














          2












          2








          2







          Using



          #df['Start Time']=pd.to_datetime(df['Start Time'])
          df1=df[df['Start Time'].dt.month==6].copy()





          share|improve this answer













          Using



          #df['Start Time']=pd.to_datetime(df['Start Time'])
          df1=df[df['Start Time'].dt.month==6].copy()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 2:34









          Wen-BenWen-Ben

          112k83368




          112k83368













          • Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

            – Dawn17
            Nov 15 '18 at 2:38











          • @Dawn17 try run my marked line

            – Wen-Ben
            Nov 15 '18 at 2:42



















          • Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

            – Dawn17
            Nov 15 '18 at 2:38











          • @Dawn17 try run my marked line

            – Wen-Ben
            Nov 15 '18 at 2:42

















          Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

          – Dawn17
          Nov 15 '18 at 2:38





          Can only use .dt accessor with datetimelike values Getting this error. I assume the datas are in string.

          – Dawn17
          Nov 15 '18 at 2:38













          @Dawn17 try run my marked line

          – Wen-Ben
          Nov 15 '18 at 2:42





          @Dawn17 try run my marked line

          – Wen-Ben
          Nov 15 '18 at 2:42




















          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%2f53311599%2ffiltering-pandas-column-with-specific-conditions%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

          Bressuire

          Vorschmack

          Quarantine