一维列的值在附加到 Pandas 数据帧时强制为零

问题描述 投票:0回答:1
# set the targets: normal=0, tumor=1

y_normal = np.zeros(6485)

y_tumor = np.ones(1348)

combined_targets = np.concatenate([y_normal,y_tumor],axis=0)

combined_targets.shape

combined_targets = pd.DataFrame(combined_targets)
combined_targets.columns = ["target"]

combined_targets.value_counts()

final_train_df = combined_df
final_train_df["target"]= combined_targets

final_train_df['target'].value_counts()

如果我直接赋值,那么值不会改变

final_train_df['target'] = np.concatenate([y_normal,y_tumor],axis=0)

数据框可在此处获取 样本数据集 列值变化

由 numpy 创建的列中的值然后转换为数据帧,被强制为零。即使添加为 np.array,这些值也会被强制为零。我在 google colab 工作,之前没有遇到过这个问题

pandas jupyter-notebook google-colaboratory
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.