参考:https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html
语法格式
ndarray.flatten(order='C')
order: “C”表示按行(C-style)顺序折叠。“F”表示按列(Fortran-style)顺序进行平化。' A '表示:如果A在内存中是Fortran连续的,则按列顺序平化,否则按行顺序平化。“K”表示按元素在内存中出现的顺序平坦化。默认为' C '。
返回:一个输入数组的一个拷贝,平展为一维的ndarray。
代码示例
import pandas as pd
import numpy as np
#利用列表创建DataFrame
data = [[0,"negative",2],[1,"negative",6],[2,"positive",0],[3,"positive",2]]
b = np.array(data)
print(b)
# output
# [['0' 'negative' '2']
# ['1' 'negative' '6']
# ['2' 'positive' '0']
# ['3' 'positive' '2']]
print(b.flatten())
# output
# ['0' 'negative' '2' '1' 'negative' '6' '2' 'positive' '0' '3' 'positive' '2']
标签:positive,平化,negative,flatten,numpy,ndarray From: https://www.cnblogs.com/chaimy/p/17355026.html