[英]Change dataframe from stacked to unstacked in Pandas
在IRIS数据集上,当我将序列转换为数据X_test.iloc[datapoint]].to_frame()
( X_test.iloc[datapoint]].to_frame()
)时,其输出方式(堆叠方式)如下:
sepal length (cm) 5.5
sepal width (cm) 2.6
petal length (cm) 4.4
petal width (cm) 1.2
当我将一系列点的列表转换为数据df = df.append(result, ignore_index=True)
( df = df.append(result, ignore_index=True)
)时,显示方式如下(未堆叠):
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
0 5.5 2.6 5.6 1.8
如何将堆叠式布局转换为非堆叠式布局?
您需要转置或使用双列表来返回一行DataFrame:
print (X_test)
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
0 5.5 2.6 5.6 1.8
1 4.0 8.0 6.0 8.0
datapoint = 0
df = X_test.iloc[datapoint].to_frame().T
print (df)
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
0 5.5 2.6 5.6 1.8
df = X_test.iloc[[datapoint]]
print (df)
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
0 5.5 2.6 5.6 1.8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.