python - 数据未存储在 pandas DataFrame 中
问题描述
我正在尝试在 python 中向 pandas DataFrame 添加一些数据,但由于某种原因,代码只是通过我的方法运行而没有添加数据。
打印log_return
显示值,以便 DataFrame 不为空。
def __init__(self, stocks):
self.log_return = pd.DataFrame()
self.simple_return = pd.DataFrame()
self.annual_return = pd.Series()
self.covariance = pd.DataFrame()
self.correlation = pd.DataFrame()
self.nstocks = int
self.portfolio_returns = []
self.portfolio_volatilities = []
self.log_return = self.get_log_return()
self.simple_return = self.get_simple_return()
self.annual_return = self.get_annual_return()
self.covariance = self.get_covariance()
self.correlation = self.get_correlation()
self.nstocks = len(stocks)
def get_log_return(self):
self.update_log_return()
return self.log_return
def get_covariance(self):
self.update_covariance()
return self.covariance
def update_covariance(self):
self.covariance = self.log_return.cov() * 250
def update_log_return(self):
self.log_return = np.log(self.data / self.data.shift(1))
解决方案
推荐阅读
- android - 如何更改自定义通知背景颜色(奥利奥及以上)?
- pattern-recognition - 如何在 MAP 中获取由 = / 给出的正则化参数
- html - 围绕内容的基本表格
- angular - Angular:如何为给定的时间戳获取 n 小时/ n 天前的 DateTime
- javascript - 如何在反应中消失“按钮”元素?
- c - 如何控制 popen() 创建的管道?
- c++ - 如何将 rapidjson::Value& 传递给函数?
- python-3.x - 如何访问类中子函数的变量?
- javascript - 如何在 if-else 循环中编写 while 循环
- flutter - 如何在线性布局Android中像内容一样在行中设置容器