How to filter or select rows that contain only dates in a pandas column Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to return only the Date from a SQL Server DateTime datatypeSelecting multiple columns in a pandas dataframeRenaming columns in pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet statistics for each group (such as count, mean, etc) using pandas GroupBy?Get list from pandas DataFrame column headersFiltering Pandas DataFrames on dates

Did Krishna say in Bhagavad Gita "I am in every living being"

Can anything be seen from the center of the Boötes void? How dark would it be?

How fail-safe is nr as stop bytes?

What initially awakened the Balrog?

Why wasn't DOSKEY integrated with COMMAND.COM?

How to install press fit bottom bracket into new frame

Significance of Cersei's obsession with elephants?

Is it fair for a professor to grade us on the possession of past papers?

Drawing without replacement: why is the order of draw irrelevant?

Dating a Former Employee

Hangman Game with C++

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

How can I reduce the gap between left and right of cdot with a macro?

How to write the following sign?

Why aren't air breathing engines used as small first stages?

Most bit efficient text communication method?

Can the Great Weapon Master feat's "Power Attack" apply to attacks from the Spiritual Weapon spell?

Using audio cues to encourage good posture

What is this clumpy 20-30cm high yellow-flowered plant?

Disembodied hand growing fangs

AppleTVs create a chatty alternate WiFi network

How could we fake a moon landing now?

What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?

How to react to hostile behavior from a senior developer?



How to filter or select rows that contain only dates in a pandas column



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to return only the Date from a SQL Server DateTime datatypeSelecting multiple columns in a pandas dataframeRenaming columns in pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet statistics for each group (such as count, mean, etc) using pandas GroupBy?Get list from pandas DataFrame column headersFiltering Pandas DataFrames on dates



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have a pandas data frame, with a column as follows:



df["Date"]
2015-04-11 00:00:00
2015-03-11 00:00:00
NaN
2014-11-15 00:00:00
its not available
2017-01-27 00:00:00
2016-05-21 00:00:00
was not detected
2015-09-16 00:00:00
incomplete
...


I would like to filter out only those rows that contain the dates.



df["Date"]
2015-04-11 00:00:00
2015-03-11 00:00:00
2014-11-15 00:00:00
2017-01-27 00:00:00
2016-05-21 00:00:00
2015-09-16 00:00:00
....


Please let me know if there is a way to filter the dates. Thank you










share|improve this question




























    2















    I have a pandas data frame, with a column as follows:



    df["Date"]
    2015-04-11 00:00:00
    2015-03-11 00:00:00
    NaN
    2014-11-15 00:00:00
    its not available
    2017-01-27 00:00:00
    2016-05-21 00:00:00
    was not detected
    2015-09-16 00:00:00
    incomplete
    ...


    I would like to filter out only those rows that contain the dates.



    df["Date"]
    2015-04-11 00:00:00
    2015-03-11 00:00:00
    2014-11-15 00:00:00
    2017-01-27 00:00:00
    2016-05-21 00:00:00
    2015-09-16 00:00:00
    ....


    Please let me know if there is a way to filter the dates. Thank you










    share|improve this question
























      2












      2








      2








      I have a pandas data frame, with a column as follows:



      df["Date"]
      2015-04-11 00:00:00
      2015-03-11 00:00:00
      NaN
      2014-11-15 00:00:00
      its not available
      2017-01-27 00:00:00
      2016-05-21 00:00:00
      was not detected
      2015-09-16 00:00:00
      incomplete
      ...


      I would like to filter out only those rows that contain the dates.



      df["Date"]
      2015-04-11 00:00:00
      2015-03-11 00:00:00
      2014-11-15 00:00:00
      2017-01-27 00:00:00
      2016-05-21 00:00:00
      2015-09-16 00:00:00
      ....


      Please let me know if there is a way to filter the dates. Thank you










      share|improve this question














      I have a pandas data frame, with a column as follows:



      df["Date"]
      2015-04-11 00:00:00
      2015-03-11 00:00:00
      NaN
      2014-11-15 00:00:00
      its not available
      2017-01-27 00:00:00
      2016-05-21 00:00:00
      was not detected
      2015-09-16 00:00:00
      incomplete
      ...


      I would like to filter out only those rows that contain the dates.



      df["Date"]
      2015-04-11 00:00:00
      2015-03-11 00:00:00
      2014-11-15 00:00:00
      2017-01-27 00:00:00
      2016-05-21 00:00:00
      2015-09-16 00:00:00
      ....


      Please let me know if there is a way to filter the dates. Thank you







      python pandas datetime






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 20:20









      user9463814user9463814

      606




      606






















          2 Answers
          2






          active

          oldest

          votes


















          4














          Using to_datetime + errors='coerce' with notna



          df=df.loc[pd.to_datetime(df.Date,errors='coerce').notna()].copy()
          df

          Out[925]:
          Date
          0 2015-04-11 00:00:00
          1 2015-03-11 00:00:00
          3 2014-11-15 00:00:00
          5 2017-01-27 00:00:00
          6 2016-05-21 00:00:00
          8 2015-09-16 00:00:00





          share|improve this answer























          • ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

            – cs95
            Mar 8 at 20:51


















          1














          I'm assuming because they are mixed dates and strings that the column is full of object and not datetime datatype. Are there no actual times in your dataframe? If not (meaning they are all 00:00:00) you can do a partial string search for the 0's.



          df[df['Date'].str.contains('00:00:00')]






          share|improve this answer























            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%2f55070463%2fhow-to-filter-or-select-rows-that-contain-only-dates-in-a-pandas-column%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









            4














            Using to_datetime + errors='coerce' with notna



            df=df.loc[pd.to_datetime(df.Date,errors='coerce').notna()].copy()
            df

            Out[925]:
            Date
            0 2015-04-11 00:00:00
            1 2015-03-11 00:00:00
            3 2014-11-15 00:00:00
            5 2017-01-27 00:00:00
            6 2016-05-21 00:00:00
            8 2015-09-16 00:00:00





            share|improve this answer























            • ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

              – cs95
              Mar 8 at 20:51















            4














            Using to_datetime + errors='coerce' with notna



            df=df.loc[pd.to_datetime(df.Date,errors='coerce').notna()].copy()
            df

            Out[925]:
            Date
            0 2015-04-11 00:00:00
            1 2015-03-11 00:00:00
            3 2014-11-15 00:00:00
            5 2017-01-27 00:00:00
            6 2016-05-21 00:00:00
            8 2015-09-16 00:00:00





            share|improve this answer























            • ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

              – cs95
              Mar 8 at 20:51













            4












            4








            4







            Using to_datetime + errors='coerce' with notna



            df=df.loc[pd.to_datetime(df.Date,errors='coerce').notna()].copy()
            df

            Out[925]:
            Date
            0 2015-04-11 00:00:00
            1 2015-03-11 00:00:00
            3 2014-11-15 00:00:00
            5 2017-01-27 00:00:00
            6 2016-05-21 00:00:00
            8 2015-09-16 00:00:00





            share|improve this answer













            Using to_datetime + errors='coerce' with notna



            df=df.loc[pd.to_datetime(df.Date,errors='coerce').notna()].copy()
            df

            Out[925]:
            Date
            0 2015-04-11 00:00:00
            1 2015-03-11 00:00:00
            3 2014-11-15 00:00:00
            5 2017-01-27 00:00:00
            6 2016-05-21 00:00:00
            8 2015-09-16 00:00:00






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 20:21









            Wen-BenWen-Ben

            127k83872




            127k83872












            • ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

              – cs95
              Mar 8 at 20:51

















            • ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

              – cs95
              Mar 8 at 20:51
















            ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

            – cs95
            Mar 8 at 20:51





            ++ for also adding the copy() to avoid possible SettingWithCopyWarning later.

            – cs95
            Mar 8 at 20:51













            1














            I'm assuming because they are mixed dates and strings that the column is full of object and not datetime datatype. Are there no actual times in your dataframe? If not (meaning they are all 00:00:00) you can do a partial string search for the 0's.



            df[df['Date'].str.contains('00:00:00')]






            share|improve this answer



























              1














              I'm assuming because they are mixed dates and strings that the column is full of object and not datetime datatype. Are there no actual times in your dataframe? If not (meaning they are all 00:00:00) you can do a partial string search for the 0's.



              df[df['Date'].str.contains('00:00:00')]






              share|improve this answer

























                1












                1








                1







                I'm assuming because they are mixed dates and strings that the column is full of object and not datetime datatype. Are there no actual times in your dataframe? If not (meaning they are all 00:00:00) you can do a partial string search for the 0's.



                df[df['Date'].str.contains('00:00:00')]






                share|improve this answer













                I'm assuming because they are mixed dates and strings that the column is full of object and not datetime datatype. Are there no actual times in your dataframe? If not (meaning they are all 00:00:00) you can do a partial string search for the 0's.



                df[df['Date'].str.contains('00:00:00')]







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 20:24









                55thSwiss55thSwiss

                171111




                171111



























                    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%2f55070463%2fhow-to-filter-or-select-rows-that-contain-only-dates-in-a-pandas-column%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

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко