<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" id="owaParaStyle" style="">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
</head>
<body dir="ltr" tabindex="0" id="">
<pre style="word-wrap:break-word; font-size:10.0pt; font-family:Tahoma; color:black">
Boris Vladimir Comi <glez_b@comunidad.unam.mx> escrito:
</pre>
<div>
<div name="divtagdefaultwrapper" id="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:#000000; margin:0">
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
I found a way to create daily averages of many variables, for example of a database that has the following structure:</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
Fecha,Time, DirViento, MagViento, Temperatura, Humedad, PreciAcu.</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
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:</p>
<pre class="lang-py prettyprint prettyprinted" style="margin-top:0px; margin-bottom:10px; padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(238,238,238); font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif; overflow:auto; width:auto; max-height:600px; word-wrap:normal; line-height:18px"><code style="margin:0px; padding:0px; border:0px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">import</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> numpy </span><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">as</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> np
</span><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">import</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> pandas </span><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">as</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> pd
data </span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> pd</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">read_csv</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">(</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'tancoyol.csv'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">)</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">
index5</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">data</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">set_index</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">([</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'Fecha'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">,</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'Hora'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">],</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">inplace</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">True</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">)</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">
grouped </span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> index5</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">groupby</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">(</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">level</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="lit" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">0</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">)</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">
stat_cea </span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> grouped</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">agg</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">({</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'Temperatura'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">:</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">np</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">mean</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">,</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'Humedad'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">:</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">np</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">mean</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">,</span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'PreciAcu'</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">:</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">np</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">.</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">sum</span><span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">})</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">
</span><span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(0,0,139)">print</span><span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> </span><span class="str" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'Done............'</span></code></pre>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
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?</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
In summary,i need to obtain 3 columns from the DirViento column agregate to datafile.</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
DirViento<br>
1/07/2011 00:00:00<br>
1/07/2011 00:15:00<br>
1/07/2011 00:30:00<br>
1/07/2011 00:45:00<br>
2/07/2011 00:00:00<br>
2/07/2011 00:15:00<br>
2/07/2011 00:30:00<br>
2/07/2011 00:45:00<br>
.<br>
.<br>
.</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
Specifically:</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
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).</p>
<p style="margin-right:0px; margin-bottom:1em; margin-left:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; background-color:rgb(255,255,255); clear:both; font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif; line-height:18px">
How I can achieve this?</p>
</div>
</div>
</body>
</html>