Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75391
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <skip.montanaro@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.052 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'toss': 0.09; 'cc:addr :python-list': 0.11; 'caching': 0.16; 'col': 0.16; 'columns': 0.16; 'expert,': 0.16; 'third,': 0.16; ':-)': 0.16; 'ignore': 0.16; 'cc:addr:python.org': 0.22; 'load': 0.23; 'mind.': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'second,': 0.31; 'them?': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'little': 0.38; 'even': 0.60; 'deleting': 0.60; 'save': 0.62; 'more': 0.64; 'android.': 0.84; 'column.': 0.84; 'measure.': 0.84; 'pickled': 0.84 |
| 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=n8gsvg7zxLXf7MPz4GbM4jVj2jzKu7xw+dhsrd7mrpU=; b=LNXDESUY1XqAgQxlih/rhtn/3ADWULaO4gjZxFAEvlnQXJY+1bqmjDUO4dWqEPPg+P 7hyMKHrIw+MDVTHBj0yb2QWasJCcBKcZPE9bsDJdrc3l3jGCX1xLJm7fS3FMGxxYQJS2 t5+nxNcPJTvDxFQVjRkV0fuYR3OzYZrqBPCHpeOt/wEa9Wc/aa5lRLxVdc6eb/P4rozO FmPvfrRUAe3OYZXLjQf/Mdndw8YSJbwRfPgIR2eVUFg3xaD+B/b5oyXJr1cmIfG2zlyM kEhF6pprVExjrZFqbYt0ND01rpT+NXc7HJHjTgCpxqTu92owu0EwYmYlH6ol4Ph7oCHV NNEg== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.82.6 with SMTP id b6mr9691792icl.51.1406764666916; Wed, 30 Jul 2014 16:57:46 -0700 (PDT) |
| In-Reply-To | <CALyJZZXMmSk8L7+P7erQSp2W4EpkbxiXmJkY-+5svfK5C3Z0kw@mail.gmail.com> |
| References | <CALyJZZXMmSk8L7+P7erQSp2W4EpkbxiXmJkY-+5svfK5C3Z0kw@mail.gmail.com> |
| Date | Wed, 30 Jul 2014 18:57:46 -0500 |
| Subject | Re: speed up pandas calculation |
| From | Skip Montanaro <skip.montanaro@gmail.com> |
| To | Vincent Davis <vincent@vincentdavis.net> |
| Content-Type | multipart/alternative; boundary=485b397dd70141177804ff71ecad |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12448.1406764670.18130.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1406764670 news.xs4all.nl 2850 [2001:888:2000:d::a6]:38589 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:75391 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
> df = pd.read_csv('nhamcsopd2010.csv' , index_col='PATCODE',
low_memory=False)
> col_init = list(df.columns.values)
> keep_col = ['PATCODE', 'PATWT', 'VDAY', 'VMONTH', 'VYEAR', 'MED1',
'MED2', 'MED3', 'MED4', 'MED5']
> for col in col_init:
> if col not in keep_col:
> del df[col]
I'm no pandas expert, but a couple things come to mind. First, where is
your code slow (profile it, even with a few well-placed prints)? If it's in
read_csv there might be little you can do unless you load those data
repeatedly, and can save a pickled data frame as a caching measure. Second,
you loop over columns deciding one by one whether to keep or toss a column.
Instead try
df = df[keep_col]
Third, if deleting those other columns is costly, can you perhaps just
ignore them?
Can't be more investigative right now. I don't have pandas on Android. :-)
Skip
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: speed up pandas calculation Skip Montanaro <skip.montanaro@gmail.com> - 2014-07-30 18:57 -0500
csiph-web