[Numpy-discussion] select column based on another column value

Roelf Schreurs Roelf.Schreurs at tibra.com
Wed Oct 9 09:46:12 EDT 2013


I have the following array and want to calculate the average per day.

Import numpy as np
from datetime import date

today =  date(today.year, today.month, 9)
yesterday = date(today.year, today.month, 8)
twodaysago = date(today.year, today.month, 7)

testdata = np.array([[today, "r", 3.2],[today, "r", 4.3],[today, "r", 5.3],[yesterday, "r", 6.3],[yesterday, "r", 9.3],[yesterday, "r", 1.3],[twodaysago, "r", 3.3],[twodaysago, "r", 1.2],[twodaysago, "r", 4.3]])

which produces
array([[datetime.date(2013, 10, 9), 'r', 3.2],
       [datetime.date(2013, 10, 9), 'r', 4.3],
       [datetime.date(2013, 10, 9), 'r', 5.3],
       [datetime.date(2013, 10, 8), 'r', 6.3],
       [datetime.date(2013, 10, 8), 'r', 9.3],
       [datetime.date(2013, 10, 8), 'r', 1.3],
       [datetime.date(2013, 10, 7), 'r', 3.3],
       [datetime.date(2013, 10, 7), 'r', 1.2],
       [datetime.date(2013, 10, 7), 'r', 4.3]], dtype=object)

And I want the output as (numbers aren't correct below):

2013-10-09, 4.54
2013-10-08, 5.43
2013-10-07, 2.76

But not sure how.


Tibra Trading Europe Limited is Authorised and Regulated by the FCA (Company No. 06061713)
Tibra Global Services Pty Limited London Branch (Company No. BR014370)
Tibra Equities Europe Limited (Company No. 07283912)
Registered in England & Wales - Level 12, 5 Aldermanbury Square London EC2V 7HR

Unless otherwise stated, this communication is neither an offer nor solicitation of an offer to sell or purchase any investment

The contents of this email including any attachments are confidential. If you have received this email in error, please advise the sender by return email and delete this email. Any unauthorised use of the contents of the email is prohibited and you must not disseminate, copy or distribute the message or use the information contained in the email or its attachments in any way.

The views or opinions expressed are the author's own and may not reflect the views or opinions of Tibra. Tibra does not guarantee the integrity of any emails or attached files. E-mails may be interfered with, may contain computer viruses or other defects. Under no circumstances do we accept liability for any loss or damage which may result from your receipt of this message or any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131009/df2c50b5/attachment.html>

More information about the NumPy-Discussion mailing list