请求帮忙看下这个问题怎么解决,我按照书上敲的代码
import pandas as pdimport numpy as np
data=[{'period':'2010','ROE':'8.31%'},{'period':'2011','ROE':'9.77%'},{'period':'2012','ROE':'5.8%'},{'period':'2013','ROE':'5.4%'},{'period':'2014','ROE':'2.08%'},{'period':'2015','ROE':'4.00%'},{'period':'2016','ROE':'4.14%'},{'period':'2017','ROE':'2.26%'},{'period':'2018','ROE':'5.02%'},{'period':'2019','ROE':'5.28%'}]
preROE=0
prePeriod=" " #用于存储上年度的年份
roe=0
length=len(data)
prePeriod=data[0]["period"]
preROE=data[0]["ROE"]
i=1
while(i<length):
period=data[i]["period"]
roe=data[i]["ROE"]
growth=roe-preROE
growth='{:.2%}'.format(growth)
print("{}年的净资产收益率比{}年的净资产收益率增加了{}".format(period,prePeriod,growth))
prePeriod=period
preROE=roe
i=i+1
目前运行,会报错TypeError: unsupported operand type(s) for -: 'str' and 'str'