Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75404
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent@vincentdavis.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.048 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'slow.': 0.09; 'toss': 0.09; 'cc:addr:python-list': 0.11; 'caching': 0.16; 'col': 0.16; 'columns': 0.16; 'expert,': 0.16; 'skip:d 60': 0.16; 'third,': 0.16; ':-)': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'seems': 0.21; 'email addr:gmail.com>': 0.22; '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; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'received:209': 0.37; 'pm,': 0.38; 'little': 0.38; 'even': 0.60; 'deleting': 0.60; 'save': 0.62; 'real': 0.63; 'more': 0.64; '30,': 0.65; 'to:addr:gmail.com': 0.65; '8bit%:21': 0.69; 'jul': 0.74; 'android.': 0.84; 'column.': 0.84; 'measure.': 0.84; 'pickled': 0.84 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=zkJk5O1PY8NKSXjBb+poL+X9vE3H3dq4eZNxfSXpWXs=; b=Upkp9w26MMlR+xdaKqMlHeUa/OfsgNvTr+QTyjWbt+sdgt8MdfEYtjgansNtF0Pkd6 0/ANAOSf36ymE+7bKR+EHe17PFtwVw9zDWPU12swJQFhbShd+wxowrNgUKwLRNJ7y5Jd ZfL9W1Io1gtYqj4Z4t1Y7AndYp+oqy5Pp0R/CaRD5umAh7Z+OsZQLEFDLHGB1Ky50fQV nKArIAj2KAu898kWnpOpuAo4ksrTFOOYPuVOChZhnqmNdZHfg9lqUNjsebaUbf9dyZPO MVm7wlJRxB0ynyAOuIfzsDaYAR+Tfy4tT7LTK/jWWOrQro+dnZ8kMP4X96BOTIQPDInj GkqA== |
| X-Gm-Message-State | ALoCoQndykWgLFbfwqdYzbvD95FRx0p8Hpo+/4KwJL08F3MhLvWLQIksN1bZ1P9tU6OTsoXxdyWY |
| X-Received | by 10.182.144.131 with SMTP id sm3mr638264obb.3.1406766529091; Wed, 30 Jul 2014 17:28:49 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <CANc-5UzCLT8ZPF2PCDMQyOqr0gqrDjFGnsRAoFBfGVmCh5-0jg@mail.gmail.com> |
| References | <CALyJZZXMmSk8L7+P7erQSp2W4EpkbxiXmJkY-+5svfK5C3Z0kw@mail.gmail.com> <CANc-5UzCLT8ZPF2PCDMQyOqr0gqrDjFGnsRAoFBfGVmCh5-0jg@mail.gmail.com> |
| From | Vincent Davis <vincent@vincentdavis.net> |
| Date | Wed, 30 Jul 2014 18:28:28 -0600 |
| Subject | Re: speed up pandas calculation |
| To | Skip Montanaro <skip.montanaro@gmail.com> |
| Content-Type | multipart/alternative; boundary=089e0158aba23fb24004ff725b5e |
| 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.12458.1406785998.18130.python-list@python.org> (permalink) |
| Lines | 118 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1406785998 news.xs4all.nl 2917 [2001:888:2000:d::a6]:52819 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:75404 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Wed, Jul 30, 2014 at 5:57 PM, Skip Montanaro <skip.montanaro@gmail.com>
wrote:
> > 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. :-)
>
So the df = df[keep_col] is not fast but it is not that slow. You made me
think of a solution to that part. just slice and copy. The only gotya is
that the keep_col have to actually exist
keep_col = ['PATCODE', 'PATWT', 'VDAYR', 'VMONTH', 'MED1', 'MED2', 'MED3',
'MED4', 'MED5']
df = df[keep_col]
The real slow part seems to be
for n in drugs:
df[n] = df[['MED1','MED2','MED3','MED4','MED5']].isin([drugs[n]]).any(1)
Vincent Davis
720-301-3003
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: speed up pandas calculation Vincent Davis <vincent@vincentdavis.net> - 2014-07-30 18:28 -0600
csiph-web