如何在Python中从dataframe加载特性和标签?
我正在尝试使用keras和tensorflow来训练网络。我有自己的缅甸语数字数据集。我正在尝试使用python开发使用神经网络的缅甸数字识别。我有train.csv文件和test.csv文件,它们的标题带有格式标签pixel0,…,pixel783。我用熊猫来加载数据帧。但我想将数据框拆分为特性和标签如何在Python中从dataframe加载特性和标签?,python,Python,我正在尝试使用keras和tensorflow来训练网络。我有自己的缅甸语数字数据集。我正在尝试使用python开发使用神经网络的缅甸数字识别。我有train.csv文件和test.csv文件,它们的标题带有格式标签pixel0,…,pixel783。我用熊猫来加载数据帧。但我想将数据框拆分为特性和标签 import pandas as pd dataframe = pd.read_csv("mmdigitstrain.csv") dataframe2 = pd.read_csv("mmdigi
import pandas as pd
dataframe = pd.read_csv("mmdigitstrain.csv")
dataframe2 = pd.read_csv("mmdigitstest.csv")
(X_train, y_train) = splitfeaturesandlabelfromdataframe
(X_test, y_test) = splitfeaturesandlabelfromdataframe2
如果数据帧包含最后一列作为标签
列。然后使用以下命令
X_train=dataframe.iloc[:,:-1]
Y_train=dataframe.iloc[:,-1:]
根据下面的评论更新。现在将数据帧w.r.t子集到列名标签
另一种方法是组合/合并两个数据帧,并尝试使用您必须将数据放在numpy数组上
import pandas as pd
import numpy as np
df_train = pd.read_csv("mmdigitstrain.csv")
df_test = pd.read_csv("mmdigitstest.csv")
y_train=df_train['label'].to_numpy()
#check the shape should bd nbofitem x 1 in train dataset
print(y_train.shape)
X_train=df_train.drop(columns=['label']).to_numpy()
check the shape should bd nbofitem x 780 in train dataset
print(X_train.shape)
y_test=df_test['label'].to_numpy()
#check the shape should bd nbofitem x 1 in test dataset
print(y_test.shape)
X_test=df_test.drop(columns=['label']).to_numpy()
check the shape should bd nbofitem x 780 in test dataset
print(X_test.shape)
请在数据框中提供标签列的名称标签列的名称是label。在csv文件中添加数据片段标签列是数据框中的第一列。
import pandas as pd
import numpy as np
df_train = pd.read_csv("mmdigitstrain.csv")
df_test = pd.read_csv("mmdigitstest.csv")
y_train=df_train['label'].to_numpy()
#check the shape should bd nbofitem x 1 in train dataset
print(y_train.shape)
X_train=df_train.drop(columns=['label']).to_numpy()
check the shape should bd nbofitem x 780 in train dataset
print(X_train.shape)
y_test=df_test['label'].to_numpy()
#check the shape should bd nbofitem x 1 in test dataset
print(y_test.shape)
X_test=df_test.drop(columns=['label']).to_numpy()
check the shape should bd nbofitem x 780 in test dataset
print(X_test.shape)