ElinaElizabeth 发表于 2020-11-24 19:25:52

帮我看看这段代码为什么出错?

代码的目的是把日度数据转化为取平均值后的周度数据
df = pd.read_excel('statebond+corpbond1+10.xlsx',sheet_name = 'Table')
df['statebond_1'] = pd.to_datetime(df['statebond_1'])
#调用pandas的to_datetime函数,将数据转换为时间序列数据
df['statebond_10'] = pd.to_datetime(df['statebond_10'])
df['companybond_10'] = pd.to_datetime(df['companybond_10'])

assert isinstance(df.resample, object)
state_1 = df.resample('W', on="statebond_1").mean()
print('1year state bond in week',state_1)
state_10 = df.resample('W', on="statebond_10").mean()
print('10year state bond in week',state_10)
corp_10 = df.resample('W', on="companybond_10").mean()
print('10year corp bond in week',corp_10)

suchocolate 发表于 2020-11-24 19:54:05

全部代码,数据文件,报错提示,都发上来。另外发代码用代码格式你的代码
页: [1]
查看完整版本: 帮我看看这段代码为什么出错?