OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Pandas, group by function and .mean()

  • Thread starter Thread starter Vanchi23
  • Start date Start date
V

Vanchi23

Guest
enter image description here


Hello, I'm new with pandas. I am working with this data-frame and would like to get a table with the average precipitation for each month. I'm following an online course and they used the next line of code to do it:

seattle['month']=seattle['date'].dt.month

seattle['month_name']=seattle['date'].dt.month_name()

monthly_precip = seattle.groupby(['month', 'month_name']).mean()[['precipitation']].reset_index() monthly_precip

In the course it worked well but, when I write it in my jupyter-notebook, it shows me the following error:

TypeError: agg function failed [how->mean,dtype->object]

I tried to change the data type of the new column month from int32 to int64. That is the difference that I saw from the course but honestly I don't know why and also didn't work

Code:
seattle['month'].astype(np.int64)
<p><img src="https://i.sstatic.net/j48yh.png" alt="enter image description here" /></p>
<p>Hello, I'm new with pandas. I am working with this data-frame and would like to get a table with the average precipitation for each month. I'm following an online course and they used the next line of code to do it:</p>
<p>seattle['month']=seattle['date'].dt.month</p>
<p>seattle['month_name']=seattle['date'].dt.month_name()</p>
<p>monthly_precip = seattle.groupby(['month', 'month_name']).mean()[['precipitation']].reset_index()
monthly_precip</p>
<p>In the course it worked well but, when I write it in my jupyter-notebook, it shows me the following error:</p>
<blockquote>
<p>TypeError: agg function failed [how->mean,dtype->object]</p>
</blockquote>
<p>I tried to change the data type of the new column <code>month</code> from int32 to int64. That is the difference that I saw from the course but honestly I don't know why and also didn't work</p>
<pre><code>seattle['month'].astype(np.int64)
</code></pre>
 

Latest posts

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top