Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'cc:addr:python-list': 0.11; 'chunks': 0.16; 'col': 0.16; 'loops': 0.16; 'numpy': 0.16; 'selections': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'programming': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'skip': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'message- id:@mail.gmail.com': 0.30; 'closer': 0.31; 'class': 0.32; 'languages': 0.32; 'another': 0.32; 'operate': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'unit': 0.37; 'list': 0.37; 'pm,': 0.38; 'expression': 0.60; '30,': 0.65; 'jul': 0.74; 'attention': 0.75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=isbG4of5gssVHFHmhTykd/uS/AttvSgv+kqgmCrzIFQ=; b=ll2Ycxp1JFghLVhLBnb7FECZGK//ZLsnqq6mIfnFkzkEWRq4zxcy+yp+vZQ2kw6qol RH/R79An+uDjczQLUgdTnpNE9gye35sOZLQBbgPRbNLpm0xWeE9izB8DQcDCdTwog8mU aNeIZR7lKs6HLy8Pf3Oz3vnn3ev9MR9rrG/v1BdFy0VLuzS7PcOlAFBTHAQTM1VlSf1Y q861rY1TJj0B1qcBnMIZR2gNbGOEQOVjBpJ/zXvgd8nszhw/Wd95OOijwMnnokDDoZsJ EYjw6UnUNPkawvOt/yyN7gG/bKurg+glgN/YzxR7PviWtZpk6sbJ9VByoCrFdAWh/MBM wvlg== MIME-Version: 1.0 X-Received: by 10.42.208.70 with SMTP id gb6mr10270716icb.89.1406773739957; Wed, 30 Jul 2014 19:28:59 -0700 (PDT) In-Reply-To: References: Date: Wed, 30 Jul 2014 21:28:59 -0500 Subject: Re: speed up pandas calculation From: Skip Montanaro To: Chris Kaynor Content-Type: text/plain; charset=UTF-8 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406773743 news.xs4all.nl 2908 [2001:888:2000:d::a6]:58510 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75397 On Wed, Jul 30, 2014 at 8:11 PM, Chris Kaynor wrote: > Another way to write this, using a list expression (untested): > new_df = [col for col in df if col.value in keep_col] As I am learning (often painfully) with pandas and JavaScript+(d3 or jQuery), loops are the enemy. You want to operate on large chunks of data simultaneously. In pandas, those chunks are thinly disguised numpy arrays. In JS+(ds or jQuery), those chunks are selections from the DOM. I should have paid closer attention to the APL unit of my programming languages survey class in college. Skip