[Tutor] Getting daily averages with pandas

Boris Vladimir Comi glez_b at comunidad.unam.mx
Sat Oct 12 03:18:52 CEST 2013



Boris Vladimir Comi <glez_b at comunidad.unam.mx> escrito:



I found a way to create daily averages of many variables, for example of a database that has the following structure:

Fecha,Time, DirViento, MagViento, Temperatura, Humedad, PreciAcu.

Each column is daily data every 15 minutes. I share the code, which, with the help of your comments I have adapted to my project. The code calculates the average of the columns Temperatura and Humedad as well as the sum of column PreciAcu. The code is as follows:

import numpy as np
import pandas as pd


data = pd.read_csv('tancoyol.csv')
index5=data.set_index(['Fecha','Hora'],inplace=True)

grouped = index5.groupby(level=0)
stat_cea = grouped.agg({'Temperatura':np.mean,'Humedad':np.mean,'PreciAcu':np.sum})
print 'Done............'

Now I have one more question, I need to convert to radians the DirViento column, how I can do this and how can add this new column to my data file?

In summary,i need to obtain 3 columns from the DirViento column agregate to datafile.

DirViento
1/07/2011 00:00:00
1/07/2011 00:15:00
1/07/2011 00:30:00
1/07/2011 00:45:00
2/07/2011 00:00:00
2/07/2011 00:15:00
2/07/2011 00:30:00
2/07/2011 00:45:00
.
.
.

Specifically:

First I need to convert the values of DirViento column to Radians (This should be a new column called Rad) Second I need to get the sine of Rad column (This should be a new column called Sin) Third I need to get the cosine of Rad column (This should be a new column called Cos).

How I can achieve this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131012/b5c08f83/attachment.html>


More information about the Tutor mailing list