Improving pandas speed for deriving data from other datasets2019 Community Moderator Electionpandas count values for last 7 days from each dateHow to fill missing value based on other columns in Pandas dataframe?Plotting two pandas dataframe columns against each otherImprove Pandas dataframe filtering speedSeries data structure in pandasHow to populate pandas series w/ values from another df?Drop Duplicate but conserve data in other columns with pandasResampling pandas Dataframe keeping other columnsAllocation from a central stock in PandasNumpy array from pandas dataframe

What is the term when two people sing in harmony, but they aren't singing the same notes?

How will losing mobility of one hand affect my career as a programmer?

Can a malicious addon access internet history and such in chrome/firefox?

Left multiplication is homeomorphism of topological groups

Perfect riffle shuffles

How to interpret the phrase "t’en a fait voir à toi"?

Teaching indefinite integrals that require special-casing

How to prevent YouTube from showing already watched videos?

Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities

word describing multiple paths to the same abstract outcome

Java - What do constructor type arguments mean when placed *before* the type?

The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?

Latex for-and in equation

How to deal with or prevent idle in the test team?

What does the "3am" section means in manpages?

Bob has never been a M before

Is it okay / does it make sense for another player to join a running game of Munchkin?

Would it be legal for a US State to ban exports of a natural resource?

Calculating the number of days between 2 dates in Excel

Have I saved too much for retirement so far?

Fast sudoku solver

Freedom of speech and where it applies

How can I successfully establish a nationwide combat training program for a large country?

I2C signal and power over long range (10meter cable)



Improving pandas speed for deriving data from other datasets



2019 Community Moderator Electionpandas count values for last 7 days from each dateHow to fill missing value based on other columns in Pandas dataframe?Plotting two pandas dataframe columns against each otherImprove Pandas dataframe filtering speedSeries data structure in pandasHow to populate pandas series w/ values from another df?Drop Duplicate but conserve data in other columns with pandasResampling pandas Dataframe keeping other columnsAllocation from a central stock in PandasNumpy array from pandas dataframe










0












$begingroup$


I don't want to filter the set I'm starting with or perform mathematical operations on it. Instead, I want to count the number of entries which appear in another set based on the observations here:



Imagine I have a set like this:



year family count
1 A 5
2 B 7


Which continues for some 1000 entries.



And then I also have a separate data set which lists every single element, pretend here it's some kind of firm:



firm_id family year_started year_ended
1234 A 1234 1942
4567 B 1836 2011
...


And that continues for almost half a million entries. How do I most efficiently count the number of entries in the second data set given matches by family and years between year_started and year_ended.



Right now, I'm using an apply function:



def get_count(year, family, a=attributes):
a = a[a['family'].str.startswith(naics_prefix)]
a = a[a['year_started'].apply(lambda d: d.year) <= year]
a = a[a['year_ended'].apply(lambda d: d.year) >= year] # can be 9999-12-31, so must be python date not pandas dt
return len(a)


Invoked by



counts.progress_apply(lambda r: get_count(r['ending_year'], r['family']),
axis=1)


Which understandably takes forever.










share|improve this question









$endgroup$
















    0












    $begingroup$


    I don't want to filter the set I'm starting with or perform mathematical operations on it. Instead, I want to count the number of entries which appear in another set based on the observations here:



    Imagine I have a set like this:



    year family count
    1 A 5
    2 B 7


    Which continues for some 1000 entries.



    And then I also have a separate data set which lists every single element, pretend here it's some kind of firm:



    firm_id family year_started year_ended
    1234 A 1234 1942
    4567 B 1836 2011
    ...


    And that continues for almost half a million entries. How do I most efficiently count the number of entries in the second data set given matches by family and years between year_started and year_ended.



    Right now, I'm using an apply function:



    def get_count(year, family, a=attributes):
    a = a[a['family'].str.startswith(naics_prefix)]
    a = a[a['year_started'].apply(lambda d: d.year) <= year]
    a = a[a['year_ended'].apply(lambda d: d.year) >= year] # can be 9999-12-31, so must be python date not pandas dt
    return len(a)


    Invoked by



    counts.progress_apply(lambda r: get_count(r['ending_year'], r['family']),
    axis=1)


    Which understandably takes forever.










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      I don't want to filter the set I'm starting with or perform mathematical operations on it. Instead, I want to count the number of entries which appear in another set based on the observations here:



      Imagine I have a set like this:



      year family count
      1 A 5
      2 B 7


      Which continues for some 1000 entries.



      And then I also have a separate data set which lists every single element, pretend here it's some kind of firm:



      firm_id family year_started year_ended
      1234 A 1234 1942
      4567 B 1836 2011
      ...


      And that continues for almost half a million entries. How do I most efficiently count the number of entries in the second data set given matches by family and years between year_started and year_ended.



      Right now, I'm using an apply function:



      def get_count(year, family, a=attributes):
      a = a[a['family'].str.startswith(naics_prefix)]
      a = a[a['year_started'].apply(lambda d: d.year) <= year]
      a = a[a['year_ended'].apply(lambda d: d.year) >= year] # can be 9999-12-31, so must be python date not pandas dt
      return len(a)


      Invoked by



      counts.progress_apply(lambda r: get_count(r['ending_year'], r['family']),
      axis=1)


      Which understandably takes forever.










      share|improve this question









      $endgroup$




      I don't want to filter the set I'm starting with or perform mathematical operations on it. Instead, I want to count the number of entries which appear in another set based on the observations here:



      Imagine I have a set like this:



      year family count
      1 A 5
      2 B 7


      Which continues for some 1000 entries.



      And then I also have a separate data set which lists every single element, pretend here it's some kind of firm:



      firm_id family year_started year_ended
      1234 A 1234 1942
      4567 B 1836 2011
      ...


      And that continues for almost half a million entries. How do I most efficiently count the number of entries in the second data set given matches by family and years between year_started and year_ended.



      Right now, I'm using an apply function:



      def get_count(year, family, a=attributes):
      a = a[a['family'].str.startswith(naics_prefix)]
      a = a[a['year_started'].apply(lambda d: d.year) <= year]
      a = a[a['year_ended'].apply(lambda d: d.year) >= year] # can be 9999-12-31, so must be python date not pandas dt
      return len(a)


      Invoked by



      counts.progress_apply(lambda r: get_count(r['ending_year'], r['family']),
      axis=1)


      Which understandably takes forever.







      pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      ifly6ifly6

      1062




      1062




















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdatascience.stackexchange.com%2fquestions%2f47975%2fimproving-pandas-speed-for-deriving-data-from-other-datasets%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • 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.

          Use MathJax to format equations. MathJax reference.


          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%2fdatascience.stackexchange.com%2fquestions%2f47975%2fimproving-pandas-speed-for-deriving-data-from-other-datasets%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

          Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

          ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

          Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery