|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码的目的是把日度数据转化为取平均值后的周度数据
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) |
|