删除最后一行并扩展数据框以使用已删除的行打印数据框

发布于 2025-02-11 05:03:51 字数 734 浏览 1 评论 0原文

为什么当我尝试删除最后一行的数据框并插入新行时,它仍然显示了我尝试使用新行删除的上一行?

if self.dataframes.minute()["broker_time"].utf8().unwrap().into_iter().any(|i| i.unwrap() == candle.broker_time()) {
  let size = self.dataframes.get_timeframe(&ETimeFrames::Minute).shape();
   self.dataframes.minute = self.dataframes.minute.head(Some(size.0 - 1));
}
println!("{:#?}", self.dataframes.minute); // prints self.dataframes.minute with the last row removed

let df = df!(..).unwrap() // create df with new data with same columns as original data
self.dataframes.minute.extend(&df).unwrap();
println!("{:#?}", self.dataframes.minute); // shows the row as if it wasn't removed and extends the new df

Why is it when I try and remove the last row a dataframe and insert a new row, it still shows the previous row I tried to remove with the new row?

if self.dataframes.minute()["broker_time"].utf8().unwrap().into_iter().any(|i| i.unwrap() == candle.broker_time()) {
  let size = self.dataframes.get_timeframe(&ETimeFrames::Minute).shape();
   self.dataframes.minute = self.dataframes.minute.head(Some(size.0 - 1));
}
println!("{:#?}", self.dataframes.minute); // prints self.dataframes.minute with the last row removed

let df = df!(..).unwrap() // create df with new data with same columns as original data
self.dataframes.minute.extend(&df).unwrap();
println!("{:#?}", self.dataframes.minute); // shows the row as if it wasn't removed and extends the new df

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天气好吗我好吗 2025-02-18 05:03:51

通过使用 vstack_mut> vstack_mut 而不是

. ,因为根据文档:

vstack将块从其他块添加到此dataFrame的块

/code>起作用而不是扩展 从其他到基础内存位置的数据,因此可能导致重新分配。

可以在上面链接的文档中找到更多信息。

Fixed by using vstack_mut instead of extend

vstack_mut works instead of extend because as per the documentation:

vstack adds the chunks from other to the chunks of this DataFrame

Whereas extend appends the data from other to the underlying memory locations and thus may cause a reallocation.

More info can be found in the docs linked above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文