gpt4 book ai didi

python - 如何从现有数据集中生成一组新值?

转载 作者:行者123 更新时间:2023-12-01 01:55:48 25 4
gpt4 key购买 nike

这是一个非常广泛的问题,但我希望有人可以帮助我解决这个问题。

我有一个大数据集,我需要从中生成一些示例。生成的数据应包含可能出现在原始数据集中的值(不是随机的,但基于原始数据集仍然有意义的值)。例如:

Original Data Set

Vendor | Category | Problem Category | Initial Detection Date | Action Date | Affected Devices | Engineer | Type of Analysis | Priority

M-Operations | Cybersecurity | Bad security policies | 09/11/2017 12:00AM | 09/11/2017 3:00AM | Third party devices | John O. | Hourly Analysis | P1
M-Operations | Cybersecurity | Penetration breach | 09/11/2017 12:00AM | 09/12/2017 3:00AM | Third party devices | Samuel P. | Daily Analysis | P2
Secure Total | CERT | Bad security policies | 09/13/2017 12:00AM | 09/13/2017 3:00AM | Main frames | Samuel P. | Hourly Analysis | P1


New Data Set

Vendor | Category | Problem Category | Initial Detection Date | Action Date | Affected Devices | Engineer | Type of Analysis | Priority

M-Operations | Cybersecurity | Penetration breach | 09/20/2017 12:00AM | 09/21/2017 3:00AM | Main frames | John P. | Hourly Analysis | P1
M-Operations | CERT | Bad security policies | 09/23/2017 12:00AM | 09/23/2017 3:00AM | Mobile devices | Samuel P. | Daily Analysis | P3
Secure Total | CERT | Bad security policies | 09/29/2017 12:00AM | 09/30/2017 3:00AM | Main frames | John P. | Hourly Analysis | P2

我找到了以下链接Generate data by using existing data set这与我的问题类似,但在这种情况下,所有值都是数字,而在我的示例中,我的一些值是非数字的。如果有人能为我提供一个如何用 Python 或 R 生成这个新数据集的示例,我将非常感激,因为我内心平静。

最佳答案

这是在 R 中执行此操作的方法

# Create dataframe
original <- data.frame(Vendor = c("M-Operations", "M-Operations", "Secure Total"),
Category = c("Cybersecurity", "CERT", "CERT"),
Problem = c("Bad", "Good", "Good"))

# Create a list of all unique values in each column
l <- list(
Vendor <- unique(original$Vendor),
Category <- unique(original$Category),
Problem <- unique(original$Problem))

# Find all possible permutations
new.data <- do.call(expand.grid, l)

# assign names to the new dataset
names(new.data) <- c("Vendor", "Category", "Problem")
new.data
# Vendor Category Problem
# 1 M-Operations Cybersecurity Bad
# 2 Secure Total Cybersecurity Bad
# 3 M-Operations CERT Bad
# 4 Secure Total CERT Bad
# 5 M-Operations Cybersecurity Good
# 6 Secure Total Cybersecurity Good
# 7 M-Operations CERT Good
# 8 Secure Total CERT Good

之后,您可以按照您想要的任何方式对此数据帧进行子集化,并根据测试需要保留尽可能多的记录

关于python - 如何从现有数据集中生成一组新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50206349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com