'系列'对象在平均温度计算中不可调用

时间:2018-02-02 18:53:45

标签: python pandas series

我正在尝试计算周末的平均温度。所以我将我的日期对象转换为日期时间,并在我创建了工作日列之后。但是,当我尝试计算平均温度时,它会因为这个错误而失败。'系列'对象不可调用

这是我的代码:

var set = this.CreateBindingSet<MyView, MyViewModel>();
set.Bind(this).For(view => view.MyMvxInteraction).To(viewModel => viewModel.MyMvxInteraction).OneWay();
set.Apply();
你怎么看? 我认为这个问题出现在&#39;或&#39;因为我写的时候:

import numpy 
import pandas as pd 
import datetime as dt

def avg_weekend_temperature(df):
    df['DATEn'] = pd.to_datetime(df['DATEn'])
    df['weekday'] = df['DATEn'].dt.dayofweek()
    mean_temp_weekends = numpy.mean(df.meantempi[df.weekday == 5] or df.meantempi[df.weekday == 6])
    return mean_temp_weekends

avg_weekend_temperature(turnstile_weather)

TypeError                                 Traceback (most recent call last)
<ipython-input-39-a808adfb4fbd> in <module>()
      9     return mean_temp_weekends
     10 
---> 11 avg_weekend_temperature(turnstile_weather)

<ipython-input-39-a808adfb4fbd> in avg_weekend_temperature(df)
      5 def avg_weekend_temperature(df):
      6     df['DATEn'] = pd.to_datetime(df['DATEn'])
----> 7     df['weekday'] = df['DATEn'].dt.dayofweek()
      8     mean_temp_weekends = numpy.mean(df.meantempi[df.weekday == 5] or df.meantempi[df.weekday == 6])
      9     return mean_temp_weekends

TypeError: 'Series' object is not callable

IESn_hourly EXITSn_hourly   maxpressurei    maxdewpti   ... meanpressurei   fog rain    meanwindspdi    mintempi    meantempi   maxtempi    precipi thunder weekday
0   0   R001    2011-05-01  01:00:00    1   REGULAR 0.0 0.0 30.31   42.0    ... 30.27   0.0 0.0 5.0 50.0    60.0    69.0    0.0 0.0 6
1   1   R001    2011-05-01  05:00:00    5   REGULAR 217.0   553.0   30.31   42.0    ... 30.27   0.0 0.0 5.0 50.0    60.0    69.0    0.0 0.0 6
2   2   R001    2011-05-01  09:00:00    9   REGULAR 890.0   1262.0  30.31   42.0    ... 30.27   0.0 0.0 5.0 50.0    60.0    69.0    0.0 0.0 6
3   3   R001    2011-05-01  13:00:00    13  REGULAR 2451.0  3708.0  30.31   42.0    ... 30.27   0.0 0.0 5.0 50.0    60.0    69.0    0.0 0.0 6
4   4   R001    2011-05-01  17:00:00    17  REGULAR 4400.0  2501.0  30.31   42.0    ... 30.27   0.0 0.0 5.0 50.0    60.0    69.0    0.0 0.0 6
5 rows × 23 columns

问题在于我无法将它们组合在一起

1 个答案:

答案 0 :(得分:0)

所以我终于找到了正确的答案。 这是代码:

import numpy
import pandas as pd
import datetime as dt

def avg_weekend_temperature(df):
    df['DATEn'] = pd.to_datetime(df['DATEn'])
    df['weekday'] = df['DATEn'].dt.dayofweek
    mean_temp_weekends = numpy.mean(df.meantempi[(df.weekday == 5) | (df.weekday == 6)])
    return mean_temp_weekends

avg_weekend_temperature(turnstile_weather)

谢谢大家