如何解决固定长度的数据框覆盖
我编写了一个代码,每一轮生成大量数据。因此,我只需要存储最近10轮的数据。添加需求对象(覆盖)时,如何创建擦除最旧对象的数据框?从旧到新的观察顺序应保持不变。有没有简单的函数或数据格式可以做到这一点?
谢谢!
解决方法
您可以使用此功能:
import axios from 'axios'
interface Comment {
created_at: string;
author: string;
comment_text: string;
story_id: number;
story_title: string;
story_url: string;
parent_id: number | null;
objectID: string;
}
function getChildren(comment: Comment,allComments: Comment[]) {
const children = allComments.filter(
(c) => String(c.parent_id) === comment.objectID
);
const fullChildren = children.forEach((child) =>
getChildren(child,allComments)
);
return fullChildren;
}
const main = async () => {
const { data } =
await axios.get<{ hits: Comment[] }>(
"https://hn.algolia.com/api/v1/search?tags=comment,story_24120336"
);
data.hits.forEach((comment) => {
// Check if comment is top level
if (String(comment.parent_id) === "24120336") {
console.log(getChildren(comment,data.hits));
}
});
}
main()
为此,您必须将列表作为参数传递给函数#periodsForPredict is a 20x1 tibble
#workfile is a much larger dataset that contains duplicates of timeSeq&period with other unique data.
workfile %>%
mutate(period=as.character(period)) %>%
right_join(periodsForPredict,by='timeSeq') %>%
select(timeSeq,period) %>%
summarise(timeSeq,period)
,以便插入新项并删除第十个项(如果有)。
(我认为问题不是熊猫特定的,而是一种在数组中存储最大数量的项目的方法)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。