正如我所看到的,关于同一主题有几篇文章,但是没有一种解决方案对我有用。 `
df_cut_now = rpd.read_root(self.file_name,self.tree_name)
df = pd.DataFrame()
df = df_cut_now.query('variable>0')
rndseed = rndm
np.random.seed(rndseed)
index = list(df.index)
np.random.shuffle(index)
df.loc[:,"new_index"] = np.array(index)
df.set_index("new_index",inplace=True)
df.sort_index(inplace=True)
尽管使用.loc,我仍然收到错误消息
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
`
我尝试过:
df_cut_now = rpd.read_root(self.file_name,self.tree_name)
df = df_cut_now[df_cut_now['variable'] > 0]
rndseed = 12345
np.random.seed(rndseed)
index = list(df.index)
np.random.shuffle(index)
#df.loc[:,"new_index"] = np.array(index)
df['new_index'] = np.array(index)
df.set_index("new_index",inplace=True)
df.sort_index(inplace=True)
仍然错误消息保持不变。
我尝试通过“ df = df_cut_now.copy()”制作df的副本,然后进行混洗,但错误消息没有消失。
关于如何避免这种情况的任何想法?