Python 3.x 无法对datetimeindex调用函数
我试图在数据帧中的datetimeindex上调用一个Python 3.x 无法对datetimeindex调用函数,python-3.x,pandas,Python 3.x,Pandas,我试图在数据帧中的datetimeindex上调用一个dayofweek()。这是我的密码: v = [ [ 1582041084.72, "1989121.03" ], [ 1582041684.72, "1989121.03" ] df = pd.DataFrame.from_records(v, columns=['time', 'points']) df = df.astype({'points': 'float'}) df['time'] = pd.
dayofweek()
。这是我的密码:
v = [
[
1582041084.72,
"1989121.03"
],
[
1582041684.72,
"1989121.03"
]
df = pd.DataFrame.from_records(v, columns=['time', 'points'])
df = df.astype({'points': 'float'})
df['time'] = pd.to_datetime(df['time'], unit='s')
df = df.set_index('time')
filtered = df.between_time('10:00', '14:30')
print(filtered.index.dayofweek())
这将返回一个错误,说明'Int64Index'对象不可调用
这是df.index
的输出:
DatetimeIndex(['2020-02-19 10:01:24.720000029',
'2020-02-19 10:11:24.720000029'],
dtype='datetime64[ns]', name='time', freq=None)
dayofweek
不需要()
。
简单地做:
print(df.index.dayofweek)
dayofweek
不需要()
。
简单地做:
print(df.index.dayofweek)
请注意,这是一个属性,而不是一个方法
这意味着您应该在不使用parens的情况下使用它:
print(filtered.index.dayofweek)
您可以看到,这就是错误消息告诉您的,'Int64Index'对象
是属性的结果,它抱怨您试图将其作为函数“调用”,但它不可调用请注意,这是属性而不是方法
这意味着您应该在不使用parens的情况下使用它:
print(filtered.index.dayofweek)
您可以看到,这就是错误消息告诉您的,
'Int64Index'对象
是属性的结果,它抱怨您试图将其作为函数“调用”,但它不可调用
问题在于示例数据过滤为空数据框,请检查打印(过滤)
它不是空的…它在示例上我得到了print(df.index)DatetimeIndex(['2020-02-18 15:51:24.720000029','2020-02-18 16:01:24.720000029',dtype='datetime64[ns]',name='time',freq=None)
问题在于样本数据过滤为空数据框,检查print(过滤)
它不是空的…它在示例上我得到了打印(df.index)DatetimeIndex(['2020-02-18 15:51:24.720000029','2020-02-18 16:01:24.720000029',dtype='datetime64[ns]',name='time',freq=None)