【学习笔记】Python大数据处理与分析——数据预处理

一、数据清洗

1、唯一值与重复值

        获取唯一值的方法是采用unique()函数,用于Series对象:

s1 = pd.Series([2, 3, 4, 1, 2, 5, 3, 6, 4, 9, 5, 3, 4, 2, 1, 2])

print(s1.unique())
→[2 3 4 1 5 6 9]

        但unique()函数不能用于DataFrame对象,而drop_duplicates()函数可以:

df1 = pd.DataFrame({'a': [1, 1, 3, 2],
                    'b': [1, 1, 6, 4],
                    'c': [1, 1, 3, 9]})

print(df1.drop_duplicates())
→  a  b  c
0  1  1  1
2  3  6  3
3  2  4  9

2、缺失值

        数据缺失分两种情况:行记录缺失(数据记录丢失)和列记录缺失。

df2 = pd.DataFrame(np.arange(12).reshape(4, 3), index=[0, 1, 2, 3], columns=['a', 'b', 'c'])
df2.iloc[1, [1]] = np.nan
df2.iloc[2, [1, 2]] = np.nan

print(df2)
→  a     b     c
0  0   1.0   2.0
1  3   NaN   5.0
2  6   NaN   NaN
3  9  10.0  11.0

(1)数据删除

        删除数据意味着减少数据特征,通常用于样本数据量很大且缺失值较少的情况。dropna()函数的原型为dropna(axis, how, thresh, subset, inplace),参数分别为:

axis:默认为0,当等于0时代表的是删除空值所在的行,当等于1时删除空值所在的列。

how:默认为‘any’,表示的是删除空值所在的行或者是列,这个主要看前面的axis参数你设定是0还是1;当参数等于‘all’,表示的是删除一阵行或者是一整列都为空值的行或者列,如果你的某一行或某一列,不全为空值的话,则不会删除,即不起作用。

thresh:一个整数x,意思是保留非空值的数量不小于x的每一行或者是每一列。

subset:指定删除特定行或列的空值所在的列或行,如果axis=0,表示如果指定行x中有空值,则删除所在的列;如果axis=1,表示如果指定列x有空值,则删除空值所在的行。

inplace:默认为False,它的意思是在处理空值时,是在原数据上处理还是在先把原数据复制一份,然后在副本上处理,在副本上处理的时候,原数据不受任何影响;如果inplace设置为True,那代表你在原数据上进行处理,原数据直接受影响。

print(df2.dropna())
→  a     b     c
0  0   1.0   2.0
3  9  10.0  11.0

print(df2.dropna(axis=1))
→  a
0  0
1  3
2  6
3  9

print(df2.dropna(axis=1, how='all'))
→  a     b     c
0  0   1.0   2.0
1  3   NaN   5.0
2  6   NaN   NaN
3  9  10.0  11.0

print(df2.dropna(axis=1, how='any'))
→  a
0  0
1  3
2  6
3  9

print(df2.dropna(axis=1, thresh=3))
→  a     c
0  0   2.0
1  3   5.0
2  6   NaN
3  9  11.0

print(df2.dropna(subset=['c']))
→  a     b     c
0  0   1.0   2.0
1  3   NaN   5.0
3  9  10.0  11.0

df2.dropna(subset=['c'], inplace=True)
print(df2)
→  a     b     c
0  0   1.0   2.0
1  3   NaN   5.0
3  9  10.0  11.0

(2)数据填补

        大致分为替换缺失值(对于数值型数据,使用平均数(mean)或中位数(median)等方法不足;对于分类型数据,使用众数(mode)等方法补足)和拟合缺失值(利用其他变量做模型输入进行缺失变量预测,对于数值型数据,使用回归模型补足;对于分类型数量,使用分类模型补足)。

df2['b'].fillna(df2['b'].mean(), inplace=True)
print(df2)
→  a     b     c
0  0   1.0   2.0
1  3   5.5   5.0
2  6   5.5   NaN
3  9  10.0  11.0

df2['c'].fillna(df2['c'].median(), inplace=True)
print(df2)
→  a     b     c
0  0   1.0   2.0
1  3   5.5   5.0
2  6   5.5   5.0
3  9  10.0  11.0

(3)不处理

        很多模型对于缺失值有较高的容忍度或更灵活的处理方法,并且补齐处理只是用主观估计值来填补未知值,不一定完全符合客观事实,有时会改变原始的系统信息或引入新的噪声数据。常见能自动处理缺失值的模型有K-Nearest Neighbor、决策树模型、随机森林模型、神经网络、朴素贝叶斯、DBSCAN等,它们将缺失值忽略,不参与运算,或将缺失作为分布的状态参与建模过程。

3、异常值

        指数据整体呈现某种统计概率分布,但有部分偏离总体,在总体规律中有不合理表现的数据。对异常值的检测原则是:确保结合具体场景下数据有意义的情况下,查找不合逻辑的数值。通常有箱线图法、正态分布图法、模型法来检测。

        对异常值的处理一般有以下几种方法:

(1)不处理

(2)填充

(3)删除

(4)编码(将异常值单独作为一组值或类别)

(5)盖帽法(将某连续变量均值上下3倍标准差范围外的记录替换为上下3倍标准差值)

二、正则表达式

        对于正则表达式的语法详解此处不作说明,仅说明正则表达式的元字符如下所示:

1、字符串方法

(1)使用 % 格式化

%d 以整型输出
%ld 以长整型输出
%o 以八进制数形式输出整数
%x 以十六进制数形式输出整数
%u 以十进制数输出unsigned型数据(无符号数)
%c 用来输出一个字符
%s 用来输出一个字符串
%f 用来输出实数,以小数形式输出
%e 以指数形式输出实数
%g 根据大小自动选f格式或e格式,且不输出无意义的零

num = 13579

print("%o" % num)
→32413

print("%x" % num)
→350b

print("%u" % num)
→13579

print("%s" % num)
→13579

print("%f" % num)
→13579.000000

print("%e" % num)
→1.357900e+04

print("%g" % num)
→13579

print("%.2f" % num)
→13579.00

 (2)使用format()函数格式化

print("{}{}".format('A', 'B'))            # 不带编号,必须一一对应
→AB

print("{1}{0}{1}".format('A', 'B'))       # 带编号打乱顺序
→BAB

print("{a}{b}{a}".format(a='A', b='B'))   # 带关键字
→ABA
① 取位数
print("{:10}".format('hello'))                    # 取10位默认左对齐
→hello 

print("{0} to {1:.2f}".format(np.pi, np.pi))      # 取两位小数
→3.141592653589793 to 3.14

print("{0:5.2} to {0:5.2f}".format(np.pi, np.pi)) # 保留两位有效数字与取两位小数对比
→  3.1 to  3.14
② 进制转化
print("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(16))
→int: 16; hex: 10; oct: 20; bin: 10000

print("{0} in hex is: {0:#x}\n{1} in oct is: {0:#o}".format(18, 10))
→18 in hex is: 0x12
 10 in oct is: 0o22
③ 字符串对齐与位数补全
print("{:<20}".format("hello world!"))
→hello world!        

print("{:^20}".format("hello world!"))
→    hello world!    

print("{:>20}".format("hello world!"))
→        hello world!

print("{:*<20}".format("hello world!"))
→hello world!********

print("{:-^20}".format("hello world!"))
→----hello world!----

print("{:#>20}".format("hello world!"))
→########hello world!

print("{:0=10}".format(12345))
→0000012345

print("{:%}".format(0.125))
→12.500000%

print("my name is {name}, my age is {age}, and my QQ is {qq}.".format(name="67x", age=21, qq="409867818"))
→my name is 67x, my age is 21, and my QQ is 409867818.

position = (1, 2, 3)
print("X: {0[0]}; Y: {0[1]}; Z: {0[2]}".format(position))
→X: 1; Y: 2; Z: 3

(3)使用f-string方法格式化

name = "67x"
age = 21

print(f"my name is {name}, my age is {age}")
→my name is 67x, my age is 21

width = 10
precision = 4
value = 11 / 3

print(f"result: {value:{width}.{precision}}")
→result:      3.667

a = 10
b = 5
c = 3
pi = np.pi

print(f"{pi:{a}.{b}}")
→    3.1416

print(f"{pi:{a}.{c}f}")
→     3.142

print(f"{a * 2}")
→20

print(f"{name * 3}")
→67x67x67x

2、re模块

(1)re.match()

        函数原型为re.match(pattern, string, flags=0),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

print(re.match("www", "www.baidu.com").span())
→(0, 3)

print(re.match("com", "www.baidu.com"))
→None

str1 = "Cats are smarter than dogs"
matchObj1 = re.match(r"(.*) are (.*?) (.*)", str1, re.M | re.I)

print(matchObj1.group())
→Cats are smarter than dogs

print(matchObj1.group(1))
→Cats

print(matchObj1.group(2))
→smarter

print(matchObj1.group(3))
→than dogs

matchObj2 = re.match(r"(.*) are (.*?) .*", str1, re.M | re.I)

print(matchObj2.group())
→Cats are smarter than dogs

print(matchObj2.group(1))
→Cats

print(matchObj2.group(2))
→smarter

matchObj3 = re.match(r"(.*) are (.*) .*", str1, re.M | re.I)

print(matchObj3.group())
→Cats are smarter than dogs

print(matchObj3.group(1))
→Cats

print(matchObj3.group(2))
→smarter than

matchObj4 = re.match(r"(.*) are (.*)", str1, re.M | re.I)

print(matchObj4.group())
→Cats are smarter than dogs

print(matchObj4.group(1))
→Cats

print(matchObj4.group(2))
→smarter than dogs

        re.match(r"(.*) are (.*) .*", str1, re.M | re.I) 的具体匹配过程如下:

re.match() 函数从头开始匹配字符串 str1,尝试将其分成若干个子串,使每个子串能够匹配正则表达式模式;

匹配过程从左到右进行。模式中的 (.*) 匹配任意数量的任意字符,并将匹配的结果保存在分组 1 中。因为这是一个贪婪模式,它会尽可能多地匹配字符,直到遇到匹配模式中的下一个字符或结束位置。在这个例子中,(.*) 匹配了 "Cats";

模式中的 " are " 匹配了字符串中的 " are ";

模式中的 (.*?) 匹配任意数量的任意字符,并将匹配的结果保存在分组 2 中。因为这是一个非贪婪模式。它会尽可能少地匹配字符,直到遇到匹配模式中的下一个字符或结束位置。在这个例子中,(.*?) 匹配了 "smarter";

模式中的 " " 匹配了字符串中的空格;

.* 匹配任意数量的任意字符,并将其忽略。在这个例子中,它匹配了 "than dogs"。

(2)re.search()

        函数原型为re.search(pattern, string, flags=0),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

print(re.search("www", "www.baidu.com").span())
→(0, 3)

print(re.search("baidu", "www.baidu.com").span())
→(4, 9)

print(re.search("com", "www.baidu.com").span())
→(10, 13)

print(re.search("\.", "www.baidu.com"))
→<re.Match object; span=(3, 4), match='.'>

print(re.search("67x", "www.baidu.com"))
→None

(3)re.sub()

        函数原型为re.sub(pattern, repl, string, count=0),参数分别为:

pattern:正则表达式中的模式字符串

repl:替换的字符串,也可为一个函数

string:要被查找替换的字符串

count:模式匹配后替换的最大次数,默认为0,表示替换所有匹配

phone = "2020-221-342#67x"

print(re.sub(r"#.*$", "", phone))    # 删除#后字符
→2020-221-342

print(re.sub(r"-", "*", phone))      # 删除-符号
→2020*221*342#67x

(4)re.compile()

        函数原型为re.compile(pattern[, flags]),参数分别为:

pattern:一个字符串形式的正则表达式

flags:匹配模式,可选:

        re.I:忽略大小写;

        re.L:表示特殊字符\w、\W、\b、\B、\s、\S;

        re.M:多行模式;

        re.S:即.,并且包含换行符在内的任意字符(.不包括换行符)

        re.U:表示特殊字符集\w、\W、\b、\B、\d、\D、\s、\S;

        re.X:为增加可读性,忽略空格和#后注释

pattern1 = re.compile(r"\d+")        # 匹配至少1个数字
str2 = "LiuXin67X"

print(pattern1.match(str2))          # 查找头部没有匹配
→None

matchObj5 = pattern1.match(str2, 6, len(str2))

print(matchObj5)                     # 返回一个Match对象
→<re.Match object; span=(6, 8), match='67'>

print(matchObj5.group())
→67

print(matchObj5.start())
→6

print(matchObj5.end())
→8

print(matchObj5.span())
→(6, 8)

pattern2 = re.compile(r"([a-z]+) ([a-z]+)", re.I)
str3 = "Hello World Wide Web"
matchObj6 = pattern2.match(str3)

print(matchObj6)
→<re.Match object; span=(0, 11), match='Hello World'>

print(matchObj6.group())             # 返回匹配成功的整个子串
→Hello World

print(matchObj6.span())              # 返回匹配成功的整个子串的索引
→(0, 11)

print(matchObj6.group(1))            # 返回第一个分组匹配成功的子串
→Hello

print(matchObj6.span(1))             # 返回第一个分组匹配成功的子串的索引
→(0, 5)

print(matchObj6.group(2))            # 返回第二个分组匹配成功的子串
→World

print(matchObj6.span(2))             # 返回第二个分组匹配成功的子串的索引
→(6, 11)

print(matchObj6.groups())            # 等价于(matchObj6.groups(1), matchObj6.groups(2), ...)
→('Hello', 'World')

 (5)findall()

        函数原型为findall(string[, pos[, endpos]]),参数分别为:

string:待匹配的字符串

pos:指定字符串的起始位置,默认为0

endpos:指定字符串的结束位置,默认为字符串长度

str4 = "baidu 123 google 456."

print(pattern1.findall(str4))
→['123', '456']

print(pattern1.findall(str4, 7, 19))
→['23', '45']

 (6)finditer()

        函数原型为finditer(string[, pos[, endpos]]),参数分别为:

string:待匹配的字符串

pos:指定字符串的起始位置,默认为0

endpos:指定字符串的结束位置,默认为字符串长度

        功能是在字符串中找到正则表达式所匹配的所有子串,并把它们作为一个迭代器返回。

it = re.finditer(pattern1, str4)
for i in it:
    print(i.group())
→123
 456

(7)split()

        函数原型为re.split(pattern, string[, maxsplit=0, flag=0]),参数分别为:

pattern:匹配的正则表达式

string:要匹配的字符串

maxsplit:分割次数,默认为0,表示不限制次数

flags:标志位,控制正则表达式的匹配方式(如是否区分大小写、多行匹配等)

str5 = " baidu 123 google 456."

print(re.split("x", str4))
→['baidu 123 google 456.']

print(re.split("\W+", str4))
→['baidu', '123', 'google', '456', '']

print(re.split("\W+", str4, 1))
→['baidu', '123 google 456.']

print(re.split("\W+", str4, 2))
→['baidu', '123', 'google 456.']

print(re.split("(\W+)", str4))
→['baidu', ' ', '123', ' ', 'google', ' ', '456', '.', '']

print(re.split("\W+", str5))
→['', 'baidu', '123', 'google', '456', '']

print(re.split("(\W+)", str5))
→['', ' ', 'baidu', ' ', '123', ' ', 'google', ' ', '456', '.', '']

三、数据规整

1、聚合、分组及数据透视

(1)分组与聚合

        数据分组的核心思想是“拆分-组织-合并”,聚合通常使用聚合函数(如count()、sum()、mean()等)。

df3 = pd.DataFrame({"A": ['a', 'b', 'c', 'a', 'b', 'a'], "B": [10, 15, 5, 2, 8, 4]})
df4 = pd.DataFrame({"A": ['a', 'b', 'c', 'b', 'a'], "B1": [3, 5, 6, 8, 9], "B2": [2, 5, 9, 6, 8]})
combine1 = df3["B"].groupby(df3["A"])
combine2 = df3.groupby(df3.dtypes, axis=1)
combine3 = df4.groupby("A")

print(combine1.mean())
→A
 a     5.333333
 b    11.500000
 c     5.000000
 Name: B, dtype: float64

print(combine1.size())
→A
 a    3
 b    2
 c    1
 Name: B, dtype: int64

print(dict(list(combine2)))
→{dtype('int64'):     B
 0  10
 1  15
 2   5
 3   2
 4   8
 5   4, dtype('O'):   A
 0  a
 1  b
 2  c
 3  a
 4  b
 5  a}

print(combine1.agg("mean"))
→A
 a     5.333333
 b    11.500000
 c     5.000000
 Name: B, dtype: float64

print(combine1.agg(["mean", "sum", "std"]))
→       mean  sum       std
A                          
a   5.333333   16  4.163332
b  11.500000   23  4.949747
c   5.000000    5       NaN

print(combine3.agg({"B1": "mean", "B2": "sum"}))
→   B1  B2
A         
a  6.0  10
b  6.5  11
c  6.0   9

(2)数据透视表

df5 = pd.DataFrame({"level": ['a', 'b', 'c', 'b', 'a'],
                    "key": ["one", "two", "one", "two", "one"],
                    "num1": [3, 5, 6, 8, 9],
                    "num2": [2, 5, 9, 6, 8]})
print(df5.pivot_table(index="key", columns="level"))
→     num1           num2          
level    a    b    c    a    b    c
key                                
one    6.0  NaN  6.0  5.0  NaN  9.0
two    NaN  6.5  NaN  NaN  5.5  NaN

print(pd.crosstab(df5.key, df5.level, margins=True))    # 计算分组频率
→level a  b  c  All
key                
one    2  0  1    3
two    0  2  0    2
All    2  2  1    5

2、数据变换与数据规约

(1)规范化

        主要分为标准化和归一化,都属于线性变换,主要区别为:归一化只与最大值和最小值有关,容易受到极值点影响,输出范围为0~1;标准化是依据样本总体的变换,每个样本点都有贡献,输出范围为实数范围。这里使用iris数据集演示:

transfer1 = MinMaxScaler(feature_range=(0, 1))
transfer2 = StandardScaler()
iris = load_iris()
df6 = transfer1.fit_transform(iris.data)
df7 = transfer2.fit_transform(iris.data)

print(iris.data)
→[[5.1 3.5 1.4 0.2]
 [4.9 3.  1.4 0.2]
 [4.7 3.2 1.3 0.2]
 [4.6 3.1 1.5 0.2]
 [5.  3.6 1.4 0.2]
 [5.4 3.9 1.7 0.4]
 [4.6 3.4 1.4 0.3]
 [5.  3.4 1.5 0.2]
 [4.4 2.9 1.4 0.2]
 [4.9 3.1 1.5 0.1]
 [5.4 3.7 1.5 0.2]
 [4.8 3.4 1.6 0.2]
 [4.8 3.  1.4 0.1]
 [4.3 3.  1.1 0.1]
 [5.8 4.  1.2 0.2]
 [5.7 4.4 1.5 0.4]
 [5.4 3.9 1.3 0.4]
 [5.1 3.5 1.4 0.3]
 [5.7 3.8 1.7 0.3]
 [5.1 3.8 1.5 0.3]
 [5.4 3.4 1.7 0.2]
 [5.1 3.7 1.5 0.4]
 [4.6 3.6 1.  0.2]
 [5.1 3.3 1.7 0.5]
 [4.8 3.4 1.9 0.2]
 [5.  3.  1.6 0.2]
 [5.  3.4 1.6 0.4]
 [5.2 3.5 1.5 0.2]
 [5.2 3.4 1.4 0.2]
 [4.7 3.2 1.6 0.2]
 [4.8 3.1 1.6 0.2]
 [5.4 3.4 1.5 0.4]
 [5.2 4.1 1.5 0.1]
 [5.5 4.2 1.4 0.2]
 [4.9 3.1 1.5 0.2]
 [5.  3.2 1.2 0.2]
 [5.5 3.5 1.3 0.2]
 [4.9 3.6 1.4 0.1]
 [4.4 3.  1.3 0.2]
 [5.1 3.4 1.5 0.2]
 [5.  3.5 1.3 0.3]
 [4.5 2.3 1.3 0.3]
 [4.4 3.2 1.3 0.2]
 [5.  3.5 1.6 0.6]
 [5.1 3.8 1.9 0.4]
 [4.8 3.  1.4 0.3]
 [5.1 3.8 1.6 0.2]
 [4.6 3.2 1.4 0.2]
 [5.3 3.7 1.5 0.2]
 [5.  3.3 1.4 0.2]
 [7.  3.2 4.7 1.4]
 [6.4 3.2 4.5 1.5]
 [6.9 3.1 4.9 1.5]
 [5.5 2.3 4.  1.3]
 [6.5 2.8 4.6 1.5]
 [5.7 2.8 4.5 1.3]
 [6.3 3.3 4.7 1.6]
 [4.9 2.4 3.3 1. ]
 [6.6 2.9 4.6 1.3]
 [5.2 2.7 3.9 1.4]
 [5.  2.  3.5 1. ]
 [5.9 3.  4.2 1.5]
 [6.  2.2 4.  1. ]
 [6.1 2.9 4.7 1.4]
 [5.6 2.9 3.6 1.3]
 [6.7 3.1 4.4 1.4]
 [5.6 3.  4.5 1.5]
 [5.8 2.7 4.1 1. ]
 [6.2 2.2 4.5 1.5]
 [5.6 2.5 3.9 1.1]
 [5.9 3.2 4.8 1.8]
 [6.1 2.8 4.  1.3]
 [6.3 2.5 4.9 1.5]
 [6.1 2.8 4.7 1.2]
 [6.4 2.9 4.3 1.3]
 [6.6 3.  4.4 1.4]
 [6.8 2.8 4.8 1.4]
 [6.7 3.  5.  1.7]
 [6.  2.9 4.5 1.5]
 [5.7 2.6 3.5 1. ]
 [5.5 2.4 3.8 1.1]
 [5.5 2.4 3.7 1. ]
 [5.8 2.7 3.9 1.2]
 [6.  2.7 5.1 1.6]
 [5.4 3.  4.5 1.5]
 [6.  3.4 4.5 1.6]
 [6.7 3.1 4.7 1.5]
 [6.3 2.3 4.4 1.3]
 [5.6 3.  4.1 1.3]
 [5.5 2.5 4.  1.3]
 [5.5 2.6 4.4 1.2]
 [6.1 3.  4.6 1.4]
 [5.8 2.6 4.  1.2]
 [5.  2.3 3.3 1. ]
 [5.6 2.7 4.2 1.3]
 [5.7 3.  4.2 1.2]
 [5.7 2.9 4.2 1.3]
 [6.2 2.9 4.3 1.3]
 [5.1 2.5 3.  1.1]
 [5.7 2.8 4.1 1.3]
 [6.3 3.3 6.  2.5]
 [5.8 2.7 5.1 1.9]
 [7.1 3.  5.9 2.1]
 [6.3 2.9 5.6 1.8]
 [6.5 3.  5.8 2.2]
 [7.6 3.  6.6 2.1]
 [4.9 2.5 4.5 1.7]
 [7.3 2.9 6.3 1.8]
 [6.7 2.5 5.8 1.8]
 [7.2 3.6 6.1 2.5]
 [6.5 3.2 5.1 2. ]
 [6.4 2.7 5.3 1.9]
 [6.8 3.  5.5 2.1]
 [5.7 2.5 5.  2. ]
 [5.8 2.8 5.1 2.4]
 [6.4 3.2 5.3 2.3]
 [6.5 3.  5.5 1.8]
 [7.7 3.8 6.7 2.2]
 [7.7 2.6 6.9 2.3]
 [6.  2.2 5.  1.5]
 [6.9 3.2 5.7 2.3]
 [5.6 2.8 4.9 2. ]
 [7.7 2.8 6.7 2. ]
 [6.3 2.7 4.9 1.8]
 [6.7 3.3 5.7 2.1]
 [7.2 3.2 6.  1.8]
 [6.2 2.8 4.8 1.8]
 [6.1 3.  4.9 1.8]
 [6.4 2.8 5.6 2.1]
 [7.2 3.  5.8 1.6]
 [7.4 2.8 6.1 1.9]
 [7.9 3.8 6.4 2. ]
 [6.4 2.8 5.6 2.2]
 [6.3 2.8 5.1 1.5]
 [6.1 2.6 5.6 1.4]
 [7.7 3.  6.1 2.3]
 [6.3 3.4 5.6 2.4]
 [6.4 3.1 5.5 1.8]
 [6.  3.  4.8 1.8]
 [6.9 3.1 5.4 2.1]
 [6.7 3.1 5.6 2.4]
 [6.9 3.1 5.1 2.3]
 [5.8 2.7 5.1 1.9]
 [6.8 3.2 5.9 2.3]
 [6.7 3.3 5.7 2.5]
 [6.7 3.  5.2 2.3]
 [6.3 2.5 5.  1.9]
 [6.5 3.  5.2 2. ]
 [6.2 3.4 5.4 2.3]
 [5.9 3.  5.1 1.8]]

print(df6)
→[[0.22222222 0.625      0.06779661 0.04166667]
 [0.16666667 0.41666667 0.06779661 0.04166667]
 [0.11111111 0.5        0.05084746 0.04166667]
 [0.08333333 0.45833333 0.08474576 0.04166667]
 [0.19444444 0.66666667 0.06779661 0.04166667]
 [0.30555556 0.79166667 0.11864407 0.125     ]
 [0.08333333 0.58333333 0.06779661 0.08333333]
 [0.19444444 0.58333333 0.08474576 0.04166667]
 [0.02777778 0.375      0.06779661 0.04166667]
 [0.16666667 0.45833333 0.08474576 0.        ]
 [0.30555556 0.70833333 0.08474576 0.04166667]
 [0.13888889 0.58333333 0.10169492 0.04166667]
 [0.13888889 0.41666667 0.06779661 0.        ]
 [0.         0.41666667 0.01694915 0.        ]
 [0.41666667 0.83333333 0.03389831 0.04166667]
 [0.38888889 1.         0.08474576 0.125     ]
 [0.30555556 0.79166667 0.05084746 0.125     ]
 [0.22222222 0.625      0.06779661 0.08333333]
 [0.38888889 0.75       0.11864407 0.08333333]
 [0.22222222 0.75       0.08474576 0.08333333]
 [0.30555556 0.58333333 0.11864407 0.04166667]
 [0.22222222 0.70833333 0.08474576 0.125     ]
 [0.08333333 0.66666667 0.         0.04166667]
 [0.22222222 0.54166667 0.11864407 0.16666667]
 [0.13888889 0.58333333 0.15254237 0.04166667]
 [0.19444444 0.41666667 0.10169492 0.04166667]
 [0.19444444 0.58333333 0.10169492 0.125     ]
 [0.25       0.625      0.08474576 0.04166667]
 [0.25       0.58333333 0.06779661 0.04166667]
 [0.11111111 0.5        0.10169492 0.04166667]
 [0.13888889 0.45833333 0.10169492 0.04166667]
 [0.30555556 0.58333333 0.08474576 0.125     ]
 [0.25       0.875      0.08474576 0.        ]
 [0.33333333 0.91666667 0.06779661 0.04166667]
 [0.16666667 0.45833333 0.08474576 0.04166667]
 [0.19444444 0.5        0.03389831 0.04166667]
 [0.33333333 0.625      0.05084746 0.04166667]
 [0.16666667 0.66666667 0.06779661 0.        ]
 [0.02777778 0.41666667 0.05084746 0.04166667]
 [0.22222222 0.58333333 0.08474576 0.04166667]
 [0.19444444 0.625      0.05084746 0.08333333]
 [0.05555556 0.125      0.05084746 0.08333333]
 [0.02777778 0.5        0.05084746 0.04166667]
 [0.19444444 0.625      0.10169492 0.20833333]
 [0.22222222 0.75       0.15254237 0.125     ]
 [0.13888889 0.41666667 0.06779661 0.08333333]
 [0.22222222 0.75       0.10169492 0.04166667]
 [0.08333333 0.5        0.06779661 0.04166667]
 [0.27777778 0.70833333 0.08474576 0.04166667]
 [0.19444444 0.54166667 0.06779661 0.04166667]
 [0.75       0.5        0.62711864 0.54166667]
 [0.58333333 0.5        0.59322034 0.58333333]
 [0.72222222 0.45833333 0.66101695 0.58333333]
 [0.33333333 0.125      0.50847458 0.5       ]
 [0.61111111 0.33333333 0.61016949 0.58333333]
 [0.38888889 0.33333333 0.59322034 0.5       ]
 [0.55555556 0.54166667 0.62711864 0.625     ]
 [0.16666667 0.16666667 0.38983051 0.375     ]
 [0.63888889 0.375      0.61016949 0.5       ]
 [0.25       0.29166667 0.49152542 0.54166667]
 [0.19444444 0.         0.42372881 0.375     ]
 [0.44444444 0.41666667 0.54237288 0.58333333]
 [0.47222222 0.08333333 0.50847458 0.375     ]
 [0.5        0.375      0.62711864 0.54166667]
 [0.36111111 0.375      0.44067797 0.5       ]
 [0.66666667 0.45833333 0.57627119 0.54166667]
 [0.36111111 0.41666667 0.59322034 0.58333333]
 [0.41666667 0.29166667 0.52542373 0.375     ]
 [0.52777778 0.08333333 0.59322034 0.58333333]
 [0.36111111 0.20833333 0.49152542 0.41666667]
 [0.44444444 0.5        0.6440678  0.70833333]
 [0.5        0.33333333 0.50847458 0.5       ]
 [0.55555556 0.20833333 0.66101695 0.58333333]
 [0.5        0.33333333 0.62711864 0.45833333]
 [0.58333333 0.375      0.55932203 0.5       ]
 [0.63888889 0.41666667 0.57627119 0.54166667]
 [0.69444444 0.33333333 0.6440678  0.54166667]
 [0.66666667 0.41666667 0.6779661  0.66666667]
 [0.47222222 0.375      0.59322034 0.58333333]
 [0.38888889 0.25       0.42372881 0.375     ]
 [0.33333333 0.16666667 0.47457627 0.41666667]
 [0.33333333 0.16666667 0.45762712 0.375     ]
 [0.41666667 0.29166667 0.49152542 0.45833333]
 [0.47222222 0.29166667 0.69491525 0.625     ]
 [0.30555556 0.41666667 0.59322034 0.58333333]
 [0.47222222 0.58333333 0.59322034 0.625     ]
 [0.66666667 0.45833333 0.62711864 0.58333333]
 [0.55555556 0.125      0.57627119 0.5       ]
 [0.36111111 0.41666667 0.52542373 0.5       ]
 [0.33333333 0.20833333 0.50847458 0.5       ]
 [0.33333333 0.25       0.57627119 0.45833333]
 [0.5        0.41666667 0.61016949 0.54166667]
 [0.41666667 0.25       0.50847458 0.45833333]
 [0.19444444 0.125      0.38983051 0.375     ]
 [0.36111111 0.29166667 0.54237288 0.5       ]
 [0.38888889 0.41666667 0.54237288 0.45833333]
 [0.38888889 0.375      0.54237288 0.5       ]
 [0.52777778 0.375      0.55932203 0.5       ]
 [0.22222222 0.20833333 0.33898305 0.41666667]
 [0.38888889 0.33333333 0.52542373 0.5       ]
 [0.55555556 0.54166667 0.84745763 1.        ]
 [0.41666667 0.29166667 0.69491525 0.75      ]
 [0.77777778 0.41666667 0.83050847 0.83333333]
 [0.55555556 0.375      0.77966102 0.70833333]
 [0.61111111 0.41666667 0.81355932 0.875     ]
 [0.91666667 0.41666667 0.94915254 0.83333333]
 [0.16666667 0.20833333 0.59322034 0.66666667]
 [0.83333333 0.375      0.89830508 0.70833333]
 [0.66666667 0.20833333 0.81355932 0.70833333]
 [0.80555556 0.66666667 0.86440678 1.        ]
 [0.61111111 0.5        0.69491525 0.79166667]
 [0.58333333 0.29166667 0.72881356 0.75      ]
 [0.69444444 0.41666667 0.76271186 0.83333333]
 [0.38888889 0.20833333 0.6779661  0.79166667]
 [0.41666667 0.33333333 0.69491525 0.95833333]
 [0.58333333 0.5        0.72881356 0.91666667]
 [0.61111111 0.41666667 0.76271186 0.70833333]
 [0.94444444 0.75       0.96610169 0.875     ]
 [0.94444444 0.25       1.         0.91666667]
 [0.47222222 0.08333333 0.6779661  0.58333333]
 [0.72222222 0.5        0.79661017 0.91666667]
 [0.36111111 0.33333333 0.66101695 0.79166667]
 [0.94444444 0.33333333 0.96610169 0.79166667]
 [0.55555556 0.29166667 0.66101695 0.70833333]
 [0.66666667 0.54166667 0.79661017 0.83333333]
 [0.80555556 0.5        0.84745763 0.70833333]
 [0.52777778 0.33333333 0.6440678  0.70833333]
 [0.5        0.41666667 0.66101695 0.70833333]
 [0.58333333 0.33333333 0.77966102 0.83333333]
 [0.80555556 0.41666667 0.81355932 0.625     ]
 [0.86111111 0.33333333 0.86440678 0.75      ]
 [1.         0.75       0.91525424 0.79166667]
 [0.58333333 0.33333333 0.77966102 0.875     ]
 [0.55555556 0.33333333 0.69491525 0.58333333]
 [0.5        0.25       0.77966102 0.54166667]
 [0.94444444 0.41666667 0.86440678 0.91666667]
 [0.55555556 0.58333333 0.77966102 0.95833333]
 [0.58333333 0.45833333 0.76271186 0.70833333]
 [0.47222222 0.41666667 0.6440678  0.70833333]
 [0.72222222 0.45833333 0.74576271 0.83333333]
 [0.66666667 0.45833333 0.77966102 0.95833333]
 [0.72222222 0.45833333 0.69491525 0.91666667]
 [0.41666667 0.29166667 0.69491525 0.75      ]
 [0.69444444 0.5        0.83050847 0.91666667]
 [0.66666667 0.54166667 0.79661017 1.        ]
 [0.66666667 0.41666667 0.71186441 0.91666667]
 [0.55555556 0.20833333 0.6779661  0.75      ]
 [0.61111111 0.41666667 0.71186441 0.79166667]
 [0.52777778 0.58333333 0.74576271 0.91666667]
 [0.44444444 0.41666667 0.69491525 0.70833333]]

print(df7)
→[[-9.00681170e-01  1.01900435e+00 -1.34022653e+00 -1.31544430e+00]
 [-1.14301691e+00 -1.31979479e-01 -1.34022653e+00 -1.31544430e+00]
 [-1.38535265e+00  3.28414053e-01 -1.39706395e+00 -1.31544430e+00]
 [-1.50652052e+00  9.82172869e-02 -1.28338910e+00 -1.31544430e+00]
 [-1.02184904e+00  1.24920112e+00 -1.34022653e+00 -1.31544430e+00]
 [-5.37177559e-01  1.93979142e+00 -1.16971425e+00 -1.05217993e+00]
 [-1.50652052e+00  7.88807586e-01 -1.34022653e+00 -1.18381211e+00]
 [-1.02184904e+00  7.88807586e-01 -1.28338910e+00 -1.31544430e+00]
 [-1.74885626e+00 -3.62176246e-01 -1.34022653e+00 -1.31544430e+00]
 [-1.14301691e+00  9.82172869e-02 -1.28338910e+00 -1.44707648e+00]
 [-5.37177559e-01  1.47939788e+00 -1.28338910e+00 -1.31544430e+00]
 [-1.26418478e+00  7.88807586e-01 -1.22655167e+00 -1.31544430e+00]
 [-1.26418478e+00 -1.31979479e-01 -1.34022653e+00 -1.44707648e+00]
 [-1.87002413e+00 -1.31979479e-01 -1.51073881e+00 -1.44707648e+00]
 [-5.25060772e-02  2.16998818e+00 -1.45390138e+00 -1.31544430e+00]
 [-1.73673948e-01  3.09077525e+00 -1.28338910e+00 -1.05217993e+00]
 [-5.37177559e-01  1.93979142e+00 -1.39706395e+00 -1.05217993e+00]
 [-9.00681170e-01  1.01900435e+00 -1.34022653e+00 -1.18381211e+00]
 [-1.73673948e-01  1.70959465e+00 -1.16971425e+00 -1.18381211e+00]
 [-9.00681170e-01  1.70959465e+00 -1.28338910e+00 -1.18381211e+00]
 [-5.37177559e-01  7.88807586e-01 -1.16971425e+00 -1.31544430e+00]
 [-9.00681170e-01  1.47939788e+00 -1.28338910e+00 -1.05217993e+00]
 [-1.50652052e+00  1.24920112e+00 -1.56757623e+00 -1.31544430e+00]
 [-9.00681170e-01  5.58610819e-01 -1.16971425e+00 -9.20547742e-01]
 [-1.26418478e+00  7.88807586e-01 -1.05603939e+00 -1.31544430e+00]
 [-1.02184904e+00 -1.31979479e-01 -1.22655167e+00 -1.31544430e+00]
 [-1.02184904e+00  7.88807586e-01 -1.22655167e+00 -1.05217993e+00]
 [-7.79513300e-01  1.01900435e+00 -1.28338910e+00 -1.31544430e+00]
 [-7.79513300e-01  7.88807586e-01 -1.34022653e+00 -1.31544430e+00]
 [-1.38535265e+00  3.28414053e-01 -1.22655167e+00 -1.31544430e+00]
 [-1.26418478e+00  9.82172869e-02 -1.22655167e+00 -1.31544430e+00]
 [-5.37177559e-01  7.88807586e-01 -1.28338910e+00 -1.05217993e+00]
 [-7.79513300e-01  2.40018495e+00 -1.28338910e+00 -1.44707648e+00]
 [-4.16009689e-01  2.63038172e+00 -1.34022653e+00 -1.31544430e+00]
 [-1.14301691e+00  9.82172869e-02 -1.28338910e+00 -1.31544430e+00]
 [-1.02184904e+00  3.28414053e-01 -1.45390138e+00 -1.31544430e+00]
 [-4.16009689e-01  1.01900435e+00 -1.39706395e+00 -1.31544430e+00]
 [-1.14301691e+00  1.24920112e+00 -1.34022653e+00 -1.44707648e+00]
 [-1.74885626e+00 -1.31979479e-01 -1.39706395e+00 -1.31544430e+00]
 [-9.00681170e-01  7.88807586e-01 -1.28338910e+00 -1.31544430e+00]
 [-1.02184904e+00  1.01900435e+00 -1.39706395e+00 -1.18381211e+00]
 [-1.62768839e+00 -1.74335684e+00 -1.39706395e+00 -1.18381211e+00]
 [-1.74885626e+00  3.28414053e-01 -1.39706395e+00 -1.31544430e+00]
 [-1.02184904e+00  1.01900435e+00 -1.22655167e+00 -7.88915558e-01]
 [-9.00681170e-01  1.70959465e+00 -1.05603939e+00 -1.05217993e+00]
 [-1.26418478e+00 -1.31979479e-01 -1.34022653e+00 -1.18381211e+00]
 [-9.00681170e-01  1.70959465e+00 -1.22655167e+00 -1.31544430e+00]
 [-1.50652052e+00  3.28414053e-01 -1.34022653e+00 -1.31544430e+00]
 [-6.58345429e-01  1.47939788e+00 -1.28338910e+00 -1.31544430e+00]
 [-1.02184904e+00  5.58610819e-01 -1.34022653e+00 -1.31544430e+00]
 [ 1.40150837e+00  3.28414053e-01  5.35408562e-01  2.64141916e-01]
 [ 6.74501145e-01  3.28414053e-01  4.21733708e-01  3.95774101e-01]
 [ 1.28034050e+00  9.82172869e-02  6.49083415e-01  3.95774101e-01]
 [-4.16009689e-01 -1.74335684e+00  1.37546573e-01  1.32509732e-01]
 [ 7.95669016e-01 -5.92373012e-01  4.78571135e-01  3.95774101e-01]
 [-1.73673948e-01 -5.92373012e-01  4.21733708e-01  1.32509732e-01]
 [ 5.53333275e-01  5.58610819e-01  5.35408562e-01  5.27406285e-01]
 [-1.14301691e+00 -1.51316008e+00 -2.60315415e-01 -2.62386821e-01]
 [ 9.16836886e-01 -3.62176246e-01  4.78571135e-01  1.32509732e-01]
 [-7.79513300e-01 -8.22569778e-01  8.07091462e-02  2.64141916e-01]
 [-1.02184904e+00 -2.43394714e+00 -1.46640561e-01 -2.62386821e-01]
 [ 6.86617933e-02 -1.31979479e-01  2.51221427e-01  3.95774101e-01]
 [ 1.89829664e-01 -1.97355361e+00  1.37546573e-01 -2.62386821e-01]
 [ 3.10997534e-01 -3.62176246e-01  5.35408562e-01  2.64141916e-01]
 [-2.94841818e-01 -3.62176246e-01 -8.98031345e-02  1.32509732e-01]
 [ 1.03800476e+00  9.82172869e-02  3.64896281e-01  2.64141916e-01]
 [-2.94841818e-01 -1.31979479e-01  4.21733708e-01  3.95774101e-01]
 [-5.25060772e-02 -8.22569778e-01  1.94384000e-01 -2.62386821e-01]
 [ 4.32165405e-01 -1.97355361e+00  4.21733708e-01  3.95774101e-01]
 [-2.94841818e-01 -1.28296331e+00  8.07091462e-02 -1.30754636e-01]
 [ 6.86617933e-02  3.28414053e-01  5.92245988e-01  7.90670654e-01]
 [ 3.10997534e-01 -5.92373012e-01  1.37546573e-01  1.32509732e-01]
 [ 5.53333275e-01 -1.28296331e+00  6.49083415e-01  3.95774101e-01]
 [ 3.10997534e-01 -5.92373012e-01  5.35408562e-01  8.77547895e-04]
 [ 6.74501145e-01 -3.62176246e-01  3.08058854e-01  1.32509732e-01]
 [ 9.16836886e-01 -1.31979479e-01  3.64896281e-01  2.64141916e-01]
 [ 1.15917263e+00 -5.92373012e-01  5.92245988e-01  2.64141916e-01]
 [ 1.03800476e+00 -1.31979479e-01  7.05920842e-01  6.59038469e-01]
 [ 1.89829664e-01 -3.62176246e-01  4.21733708e-01  3.95774101e-01]
 [-1.73673948e-01 -1.05276654e+00 -1.46640561e-01 -2.62386821e-01]
 [-4.16009689e-01 -1.51316008e+00  2.38717193e-02 -1.30754636e-01]
 [-4.16009689e-01 -1.51316008e+00 -3.29657076e-02 -2.62386821e-01]
 [-5.25060772e-02 -8.22569778e-01  8.07091462e-02  8.77547895e-04]
 [ 1.89829664e-01 -8.22569778e-01  7.62758269e-01  5.27406285e-01]
 [-5.37177559e-01 -1.31979479e-01  4.21733708e-01  3.95774101e-01]
 [ 1.89829664e-01  7.88807586e-01  4.21733708e-01  5.27406285e-01]
 [ 1.03800476e+00  9.82172869e-02  5.35408562e-01  3.95774101e-01]
 [ 5.53333275e-01 -1.74335684e+00  3.64896281e-01  1.32509732e-01]
 [-2.94841818e-01 -1.31979479e-01  1.94384000e-01  1.32509732e-01]
 [-4.16009689e-01 -1.28296331e+00  1.37546573e-01  1.32509732e-01]
 [-4.16009689e-01 -1.05276654e+00  3.64896281e-01  8.77547895e-04]
 [ 3.10997534e-01 -1.31979479e-01  4.78571135e-01  2.64141916e-01]
 [-5.25060772e-02 -1.05276654e+00  1.37546573e-01  8.77547895e-04]
 [-1.02184904e+00 -1.74335684e+00 -2.60315415e-01 -2.62386821e-01]
 [-2.94841818e-01 -8.22569778e-01  2.51221427e-01  1.32509732e-01]
 [-1.73673948e-01 -1.31979479e-01  2.51221427e-01  8.77547895e-04]
 [-1.73673948e-01 -3.62176246e-01  2.51221427e-01  1.32509732e-01]
 [ 4.32165405e-01 -3.62176246e-01  3.08058854e-01  1.32509732e-01]
 [-9.00681170e-01 -1.28296331e+00 -4.30827696e-01 -1.30754636e-01]
 [-1.73673948e-01 -5.92373012e-01  1.94384000e-01  1.32509732e-01]
 [ 5.53333275e-01  5.58610819e-01  1.27429511e+00  1.71209594e+00]
 [-5.25060772e-02 -8.22569778e-01  7.62758269e-01  9.22302838e-01]
 [ 1.52267624e+00 -1.31979479e-01  1.21745768e+00  1.18556721e+00]
 [ 5.53333275e-01 -3.62176246e-01  1.04694540e+00  7.90670654e-01]
 [ 7.95669016e-01 -1.31979479e-01  1.16062026e+00  1.31719939e+00]
 [ 2.12851559e+00 -1.31979479e-01  1.61531967e+00  1.18556721e+00]
 [-1.14301691e+00 -1.28296331e+00  4.21733708e-01  6.59038469e-01]
 [ 1.76501198e+00 -3.62176246e-01  1.44480739e+00  7.90670654e-01]
 [ 1.03800476e+00 -1.28296331e+00  1.16062026e+00  7.90670654e-01]
 [ 1.64384411e+00  1.24920112e+00  1.33113254e+00  1.71209594e+00]
 [ 7.95669016e-01  3.28414053e-01  7.62758269e-01  1.05393502e+00]
 [ 6.74501145e-01 -8.22569778e-01  8.76433123e-01  9.22302838e-01]
 [ 1.15917263e+00 -1.31979479e-01  9.90107977e-01  1.18556721e+00]
 [-1.73673948e-01 -1.28296331e+00  7.05920842e-01  1.05393502e+00]
 [-5.25060772e-02 -5.92373012e-01  7.62758269e-01  1.58046376e+00]
 [ 6.74501145e-01  3.28414053e-01  8.76433123e-01  1.44883158e+00]
 [ 7.95669016e-01 -1.31979479e-01  9.90107977e-01  7.90670654e-01]
 [ 2.24968346e+00  1.70959465e+00  1.67215710e+00  1.31719939e+00]
 [ 2.24968346e+00 -1.05276654e+00  1.78583195e+00  1.44883158e+00]
 [ 1.89829664e-01 -1.97355361e+00  7.05920842e-01  3.95774101e-01]
 [ 1.28034050e+00  3.28414053e-01  1.10378283e+00  1.44883158e+00]
 [-2.94841818e-01 -5.92373012e-01  6.49083415e-01  1.05393502e+00]
 [ 2.24968346e+00 -5.92373012e-01  1.67215710e+00  1.05393502e+00]
 [ 5.53333275e-01 -8.22569778e-01  6.49083415e-01  7.90670654e-01]
 [ 1.03800476e+00  5.58610819e-01  1.10378283e+00  1.18556721e+00]
 [ 1.64384411e+00  3.28414053e-01  1.27429511e+00  7.90670654e-01]
 [ 4.32165405e-01 -5.92373012e-01  5.92245988e-01  7.90670654e-01]
 [ 3.10997534e-01 -1.31979479e-01  6.49083415e-01  7.90670654e-01]
 [ 6.74501145e-01 -5.92373012e-01  1.04694540e+00  1.18556721e+00]
 [ 1.64384411e+00 -1.31979479e-01  1.16062026e+00  5.27406285e-01]
 [ 1.88617985e+00 -5.92373012e-01  1.33113254e+00  9.22302838e-01]
 [ 2.49201920e+00  1.70959465e+00  1.50164482e+00  1.05393502e+00]
 [ 6.74501145e-01 -5.92373012e-01  1.04694540e+00  1.31719939e+00]
 [ 5.53333275e-01 -5.92373012e-01  7.62758269e-01  3.95774101e-01]
 [ 3.10997534e-01 -1.05276654e+00  1.04694540e+00  2.64141916e-01]
 [ 2.24968346e+00 -1.31979479e-01  1.33113254e+00  1.44883158e+00]
 [ 5.53333275e-01  7.88807586e-01  1.04694540e+00  1.58046376e+00]
 [ 6.74501145e-01  9.82172869e-02  9.90107977e-01  7.90670654e-01]
 [ 1.89829664e-01 -1.31979479e-01  5.92245988e-01  7.90670654e-01]
 [ 1.28034050e+00  9.82172869e-02  9.33270550e-01  1.18556721e+00]
 [ 1.03800476e+00  9.82172869e-02  1.04694540e+00  1.58046376e+00]
 [ 1.28034050e+00  9.82172869e-02  7.62758269e-01  1.44883158e+00]
 [-5.25060772e-02 -8.22569778e-01  7.62758269e-01  9.22302838e-01]
 [ 1.15917263e+00  3.28414053e-01  1.21745768e+00  1.44883158e+00]
 [ 1.03800476e+00  5.58610819e-01  1.10378283e+00  1.71209594e+00]
 [ 1.03800476e+00 -1.31979479e-01  8.19595696e-01  1.44883158e+00]
 [ 5.53333275e-01 -1.28296331e+00  7.05920842e-01  9.22302838e-01]
 [ 7.95669016e-01 -1.31979479e-01  8.19595696e-01  1.05393502e+00]
 [ 4.32165405e-01  7.88807586e-01  9.33270550e-01  1.44883158e+00]
 [ 6.86617933e-02 -1.31979479e-01  7.62758269e-01  7.90670654e-01]]

(2)离散化

        指把连续型变量转化为离散型变量的过程,可理解为连续值的一种映射。

ages = [31, 27, 11, 38, 15, 74, 44, 32, 54, 63, 41, 23]
bins = [15, 25, 45, 65, 100]
group_names = ["A", "B", "C", "D"]
① 等宽法

        按照变量的取值范围进行区间等长度划分,从而获得切分点和切分区间。

print(list(pd.cut(ages, bins, labels=group_names)))
→['B', 'B', nan, 'B', nan, 'D', 'B', 'B', 'C', 'C', 'B', 'A']
② 等频法

        按照分位数的概念对区间进行切分,已达到每个区间频数近似相等的效果。

print(list(pd.qcut(ages, 4)))
→[Interval(26.0, 35.0, closed='right'), Interval(26.0, 35.0, closed='right'), 
Interval(10.999, 26.0, closed='right'), Interval(35.0, 46.5, closed='right'), 
Interval(10.999, 26.0, closed='right'), Interval(46.5, 74.0, closed='right'), 
Interval(35.0, 46.5, closed='right'), Interval(26.0, 35.0, closed='right'), 
Interval(46.5, 74.0, closed='right'), Interval(46.5, 74.0, closed='right'), 
Interval(35.0, 46.5, closed='right'), Interval(10.999, 26.0, closed='right')]

(3)编码

        序号编码实际上是特征的映射,并且序号编码是对有先后顺序的变量值或者变量类别进行的编码。

df8 = pd.DataFrame({"gender": ["male", "female", "male", "male", "female"]})

print(df8["gender"].replace(["male", "female"], [1.0, 0.0]))
→0    1.0
 1    0.0
 2    1.0
 3    1.0
 4    0.0
 Name: gender, dtype: float64

print(df8["gender"].map({"male": 1.0, "female": 0.0}))
→0    1.0
 1    0.0 
 2    1.0
 3    1.0
 4    0.0
 Name: gender, dtype: float64

(4)数据规约

        数据规约产生更小且保持完整性的新数据集,在规约后的数据集上进行分析和挖掘将提高效率。

① 属性规约

        属性规约通过属性合并创建新属性维数,或者通过直接删除不相关的属性来减少数据维数,从而提高数据挖掘的效率,降低计算成本。

属性规约常用方法
属性规约方法方法描述
合并属性将一些旧属性合并为新属性
逐步向前选择从一个空属性集开始,每次从原来属性集合中选择一个当前最优的属性添加到当前属性子集中,直到无法选出最优属性或满足一定阈值约束为止
逐步向后删除从全属性集开始,每次从当前属性子集中选择一个当前最差属性并将其从当前属性子集中消去
决策树归纳利用决策树的归纳方法对初始数据进行分类归纳学习,获得一个初始决策树,所有没有出现在决策树上的属性均可认为是无关属性,因此可以将这些属性删除
主成分分析用较少的变量去解释原数据中的大部分变量,将许多相关性很高的变量转化成彼此相互独立或不相关变量
② 数值规约

        用替代的、较小的数据表示形式换原始数据。这些技术可以是参数或者非参数的。

对于参数方法而言,使用模型估计数据,使得一般只需要存放模型参数而不是实际数据(离群点需存放),如回归和对数-线性模型。

存放数值规约表示的非参数方法包括: 直方图、聚类、抽样和数据立方体聚类。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/553085.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

html接入百度地图

1.申请key key申请地址&#xff1a;https://lbsyun.baidu.com/apiconsole/key#/home 注意&#xff1a;白名单设置*则所有可访问&#xff0c;正式发布保证安全需修改为域名 官方文档 https://lbsyun.baidu.com/index.php?titlejspopularGL 2.html接入示例 <!DOCTYPE …

基于51单片机智能鱼缸仿真LCD1602显示( proteus仿真+程序+设计报告+讲解视频)

基于51单片机智能鱼缸仿真LCD显示 1. 主要功能&#xff1a;2. 讲解视频&#xff1a;3. 仿真4. 程序代码5. 设计报告6. 设计资料内容清单&&下载链接资料下载链接&#xff1a; 基于51单片机智能鱼缸仿真LCD显示( proteus仿真程序设计报告讲解视频&#xff09; 仿真图prot…

基于springboot+vue+Mysql的汽车租赁系统

开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;…

04-15 周一 GitHub仓库CI服务器actions-runner和workflow yaml配置文档解析

04-15 周一 GitHub仓库CI服务器配置过程文档 时间版本修改人描述2024年4月15日10:35:52V0.1宋全恒新建文档2024年4月17日10:33:20v1.0宋全恒完成github actions CI的配置和工作流配置文件解读文档的撰写 简介 一些基础概念 前提知识 仓库介绍 地址镜像介绍https://github.…

选择生产制造项目管理系统?全面解析功能与实际应用!

生产效率和项目规划是制造企业亟需解决的难题&#xff0c;想要从容的应对这些挑战&#xff0c;离不开好用的生产制造项目管理系统。下面我们全面解析什么才能称得上是好用的生产制造项目管理系统。 一、好用的生产制造项目管理系统 什么样的项目管理系统才能算是好用呢&#x…

【QT进阶】Qt Web混合编程之VS2019 CEF的编译与使用(图文并茂超详细介绍)

往期回顾 【QT入门】Qt自定义控件与样式设计之自定义QLineEdit实现搜索编辑框-CSDN博客 【QT入门】Qt自定义控件与样式设计之自定义QTabWidget实现tab在左&#xff0c;文本水平的效果-CSDN博客【QT进阶】Qt Web混合编程之CEF、QCefView简单介绍-CSDN博客 【QT进阶】Qt Web混合编…

微服务相关

1. 微服务主要七个模块 中央管理平台&#xff1a;生产者、消费者注册&#xff0c;服务发现&#xff0c;服务治理&#xff0c;调用关系生产者消费者权限管理流量管理自定义传输协议序列化反序列化 2. 中央管理平台 生产者A在中央管理平台注册后&#xff0c;中央管理平台会给他…

2024运营级租房源码管理PHP后台+uniapp前端(app+小程序+H5)

内容目录 一、详细介绍二、效果展示1.部分代码2.效果图展示 一、详细介绍 房产系统 一款基于ThinkPHPUniapp开发的房产管理系统&#xff0c;支持小程序、H5、APP&#xff1b;包含房客、房东、经纪人三种身份。核心功能有&#xff1a;新盘销售、房屋租赁、地图找房、房源代理、…

基于SSM+Jsp+Mysql的准速达物流管理系统

开发语言&#xff1a;Java框架&#xff1a;ssm技术&#xff1a;JSPJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包…

保护视力,从 CareUEyes 开始 —— 你的电脑护眼小助手

在数字化时代&#xff0c;我们的眼睛比以往任何时候都更频繁地面对屏幕。长时间盯着电脑工作&#xff0c;不仅影响视力&#xff0c;还可能导致眼疲劳和不适。今天&#xff0c;我要向大家推荐一款专为电脑用户设计的护眼软件——CareUEyes。 CareUEyes&#xff1a;你的视力守护者…

数据大爆炸:WordCount程序的多元化执行方式

文章目录 主要内容1.左方工作区右键New,选择Map文件2.再创建mymap,myreducer,mywordcount类&#xff1a;3.打包在linux中运行&#xff0c;注意处理的文件式完全分布式文件3.1打jar包步骤&#xff1a; 4.完成内容 主要内容 尝试使用不同的方式运行wordcount程序。 1&#xff09…

【洛谷 P3366】【模板】最小生成树 题解(无向图+边集数组+Kruskal算法+最小生成树+并查集+路径压缩)

【模板】最小生成树 题目描述 如题&#xff0c;给出一个无向图&#xff0c;求出最小生成树&#xff0c;如果该图不连通&#xff0c;则输出 orz。 输入格式 第一行包含两个整数 N , M N,M N,M&#xff0c;表示该图共有 N N N 个结点和 M M M 条无向边。 接下来 M M M 行…

「Qt Widget中文示例指南」如何实现行编辑功能

Qt 是目前最先进、最完整的跨平台C开发工具。它不仅完全实现了一次编写&#xff0c;所有平台无差别运行&#xff0c;更提供了几乎所有开发过程中需要用到的工具。如今&#xff0c;Qt已被运用于超过70个行业、数千家企业&#xff0c;支持数百万设备及应用。 Line Edits&#xf…

PHP 使用 PHPMailer 发送电子邮件

1. PHPMailer 介绍 phpMailer 是一个非常强大的 php 发送邮件扩展包&#xff0c;可以设定发送邮件地址、回复地址、邮件主题、html邮件内容和上传附件等&#xff0c;使用起来非常方便。它目前有着有近 4 千万的下载量&#xff0c;是 PHP 开发者实现邮件发送功能的首选扩展包 它…

Oracle11.2.0.1,(CVE-2012-1675)漏洞解决方案

1.进入容器停止监听 docker exec -it -u 0 oracle11g bash su - oracle lsnrctl stop listener2.找到监听配置文件位置&#xff0c;修改监听文件 echo $ORACLE_HOMEvi network/admin/listener.ora #在文件底部添加 SECURE_REGISTER_LISTENER (IPC) #启动监听 lsnrctl start …

vue3:tree结构的全选和取消

实现的功能&#xff0c;上面有个选择框&#xff0c;当选中全部时&#xff0c;下方树被全选 代码&#xff1a; <template><div><el-select v-model"selectAll" style"margin-bottom: 10px;" change"handleSelectAllChange">&…

HarmonyOS开发实例:【分布式数据服务】

介绍 分布式数据服务(Distributed Data Service&#xff0c;DDS)为应用程序提供不同设备间数据分布式的能力。通过调用分布式数据接口&#xff0c;应用程序将数据保存到分布式数据库中。通过结合帐号、应用和分布式数据服务对属于不同的应用的数据进行隔离&#xff0c;保证不同…

用海豚调度器定时调度从Kafka到HDFS的kettle任务脚本

在实际项目中&#xff0c;从Kafka到HDFS的数据是每天自动生成一个文件&#xff0c;按日期区分。而且Kafka在不断生产数据&#xff0c;因此看看kettle是不是需要时刻运行&#xff1f;能不能按照每日自动生成数据文件&#xff1f; 为了测试实际项目中的海豚定时调度从Kafka到HDF…

四川易点慧电子商务抖音小店打造便捷生活新体验

随着互联网的迅猛发展&#xff0c;电子商务已经深入到人们生活的方方面面。在这个大背景下&#xff0c;四川易点慧电子商务抖音小店应运而生&#xff0c;凭借其独特的魅力和创新模式&#xff0c;迅速在电商领域崭露头角&#xff0c;成为了众多消费者追逐的焦点。 抖音小店作为新…

HTML5+CSS3小实例:菜单按钮的三种切换动画

实例:菜单按钮的三种切换动画 技术栈:HTML+CSS 效果: 源码: 【HTML】 <!DOCTYPE html> <html lang="zh-CN"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initia…
最新文章