我正在称赞一个*.csv文件。因此,我尝试创建一个类来帮助我简化数据帧上的一些操作。你知道吗
我创建了两个方法来解析包含Price列值的列z。你知道吗
def subr(self):
isone = self.df.z == 1.0
if isone.any():
atone = self.df.Price[isone].iloc[0]
self.df.loc[self.df.z.between(0.8, 2.5), 'Benchmark'] = atone
# df.loc[(df.r >= .8) & (df.r <= 1.4), 'value'] = atone
return self.df
def obtain_z(self):
"Return a column with z for E_ref"
self.z_col = self.subr()
self.dfnew = self.df.groupby((self.df.z < self.df.z.shift()).cumsum()).apply(self.z_col)
return self.dfnew
def main():
x = ParseDataBase('data.csv')
file_content = x.read_file()
new_df = x.obtain_z()
我得到以下错误:
'DataFrame' objects are mutable, thus they cannot be hashed
“DataFrame”对象是可变的,这意味着我们可以更改该帧的元素。我不确定我什么时候在散列。你知道吗
我注意到apply(self.z_col)
的用法出错了。你知道吗
我也不知道怎么修。你知道吗
您正在将
self.subr()
返回的DataFrame
self.df
传递给apply
,但实际上apply
只将函数作为参数(see examples here)。你知道吗相关问题 更多 >
编程相关推荐