我想去 1) 从FamaFrench网站读取数据 2) 将日期(月、年)转换为DateTime对象 3) 将所有退货数据转换为百分比退货(退货/100)
我下面的代码读取famafrench网站的数据。你知道吗
industry30Web =web.DataReader("30_Industry_Portfolios","famafrench")
industry30_monthlyVal = industry30Web[4]
dateInt = industry30_monthlyVal.index
conv = lambda x: datetime.datetime.strptime(str(x),'%Y%m')
dates = [conv(x) for x in dateInt]
industry30_monthlyVal.index = dates
industry30_monthlyVal.values = industry30_monthlyVal.values/100
最后一行显示AttributeError
请帮帮我,让我知道我做错了什么。你知道吗
documentation明确地指出,您不能分配给
values
属性。你知道吗但是,您可以通过执行
industry30_monthlyVal[:]= industry30_monthlyVal[:]/100
来实现您想要的当我在generic下查看源代码时pd.数据帧我发现:
该方法不能将数据写入数据帧(例如,可以覆盖的类变量)。 apply功能可能就是您想要的:
它对数据帧的工作方式相同
相关问题 更多 >
编程相关推荐