Pandas Filter by Regex AND labels combinedAdd one row to pandas DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow do I get the row count of a Pandas dataframe?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers

What is a Samsaran Word™?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

Is this draw by repetition?

How to install cross-compiler on Ubuntu 18.04?

Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)

Calculate the Mean mean of two numbers

Is it a bad idea to plug the other end of ESD strap to wall ground?

How to show a landlord what we have in savings?

How do conventional missiles fly?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

How could indestructible materials be used in power generation?

If a warlock makes a Dancing Sword their pact weapon, is there a way to prevent it from disappearing if it's farther away for more than a minute?

What is the fastest integer factorization to break RSA?

Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?

Can a virus destroy the BIOS of a modern computer?

Why do I get negative height?

How can I prove that a state of equilibrium is unstable?

Bullying boss launched a smear campaign and made me unemployable

Processor speed limited at 0.4 Ghz

What is the most common color to indicate the input-field is disabled?

Mathematica command that allows it to read my intentions

Implication of namely

My ex-girlfriend uses my Apple ID to log in to her iPad. Do I have to give her my Apple ID password to reset it?

How to find if SQL server backup is encrypted with TDE without restoring the backup



Pandas Filter by Regex AND labels combined


Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow do I get the row count of a Pandas dataframe?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers













2















I've got some big csv's. They can easily have over 300k rows and 500 columns. So obviously I like to get rid of some unneeded data in the resulting dataframe to safe resources.
There are some fix labeled columns and also some variable number of columns having similar lables but being numbered.



example=pd.DataFrame(columns=["fix","variable 1","variable 2","waste 1","waste 2"])


I want to get all these variable columns, which I can get via



example.filter(regex="var")


but I want to include "fix" as well. As df.loc doesn't allow regex' and df.filter only supports a single argument, is there a smooth way to do this? Or do I have to create a quite complex callable?



thanks in advance










share|improve this question


























    2















    I've got some big csv's. They can easily have over 300k rows and 500 columns. So obviously I like to get rid of some unneeded data in the resulting dataframe to safe resources.
    There are some fix labeled columns and also some variable number of columns having similar lables but being numbered.



    example=pd.DataFrame(columns=["fix","variable 1","variable 2","waste 1","waste 2"])


    I want to get all these variable columns, which I can get via



    example.filter(regex="var")


    but I want to include "fix" as well. As df.loc doesn't allow regex' and df.filter only supports a single argument, is there a smooth way to do this? Or do I have to create a quite complex callable?



    thanks in advance










    share|improve this question
























      2












      2








      2








      I've got some big csv's. They can easily have over 300k rows and 500 columns. So obviously I like to get rid of some unneeded data in the resulting dataframe to safe resources.
      There are some fix labeled columns and also some variable number of columns having similar lables but being numbered.



      example=pd.DataFrame(columns=["fix","variable 1","variable 2","waste 1","waste 2"])


      I want to get all these variable columns, which I can get via



      example.filter(regex="var")


      but I want to include "fix" as well. As df.loc doesn't allow regex' and df.filter only supports a single argument, is there a smooth way to do this? Or do I have to create a quite complex callable?



      thanks in advance










      share|improve this question














      I've got some big csv's. They can easily have over 300k rows and 500 columns. So obviously I like to get rid of some unneeded data in the resulting dataframe to safe resources.
      There are some fix labeled columns and also some variable number of columns having similar lables but being numbered.



      example=pd.DataFrame(columns=["fix","variable 1","variable 2","waste 1","waste 2"])


      I want to get all these variable columns, which I can get via



      example.filter(regex="var")


      but I want to include "fix" as well. As df.loc doesn't allow regex' and df.filter only supports a single argument, is there a smooth way to do this? Or do I have to create a quite complex callable?



      thanks in advance







      python pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 20:52









      TokeruTokeru

      111




      111






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Just modify your regex to do a full match for "fix":



          df.filter(regex=r"var|(^fix$)")

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []



          Another option is using Index.str.contains in the same fashion:



          df.loc[:,df.columns.str.contains(r'var|(?:^fix$)') ]

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []


          I made the group non-capturing, otherwise pandas complains.






          share|improve this answer























          • thanks, this works. Still it will get a quite confusing regex but hey ..

            – Tokeru
            Mar 7 at 21:10











          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%2f55052610%2fpandas-filter-by-regex-and-labels-combined%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









          1














          Just modify your regex to do a full match for "fix":



          df.filter(regex=r"var|(^fix$)")

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []



          Another option is using Index.str.contains in the same fashion:



          df.loc[:,df.columns.str.contains(r'var|(?:^fix$)') ]

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []


          I made the group non-capturing, otherwise pandas complains.






          share|improve this answer























          • thanks, this works. Still it will get a quite confusing regex but hey ..

            – Tokeru
            Mar 7 at 21:10















          1














          Just modify your regex to do a full match for "fix":



          df.filter(regex=r"var|(^fix$)")

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []



          Another option is using Index.str.contains in the same fashion:



          df.loc[:,df.columns.str.contains(r'var|(?:^fix$)') ]

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []


          I made the group non-capturing, otherwise pandas complains.






          share|improve this answer























          • thanks, this works. Still it will get a quite confusing regex but hey ..

            – Tokeru
            Mar 7 at 21:10













          1












          1








          1







          Just modify your regex to do a full match for "fix":



          df.filter(regex=r"var|(^fix$)")

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []



          Another option is using Index.str.contains in the same fashion:



          df.loc[:,df.columns.str.contains(r'var|(?:^fix$)') ]

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []


          I made the group non-capturing, otherwise pandas complains.






          share|improve this answer













          Just modify your regex to do a full match for "fix":



          df.filter(regex=r"var|(^fix$)")

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []



          Another option is using Index.str.contains in the same fashion:



          df.loc[:,df.columns.str.contains(r'var|(?:^fix$)') ]

          Empty DataFrame
          Columns: [fix, variable 1, variable 2]
          Index: []


          I made the group non-capturing, otherwise pandas complains.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 20:54









          coldspeedcoldspeed

          139k24154239




          139k24154239












          • thanks, this works. Still it will get a quite confusing regex but hey ..

            – Tokeru
            Mar 7 at 21:10

















          • thanks, this works. Still it will get a quite confusing regex but hey ..

            – Tokeru
            Mar 7 at 21:10
















          thanks, this works. Still it will get a quite confusing regex but hey ..

          – Tokeru
          Mar 7 at 21:10





          thanks, this works. Still it will get a quite confusing regex but hey ..

          – Tokeru
          Mar 7 at 21:10



















          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%2f55052610%2fpandas-filter-by-regex-and-labels-combined%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 у кіно

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

          Ель Греко