【问题标题】:Is there a way to check all label values of a dataset using pandas or numpy?有没有办法使用 pandas 或 numpy 检查数据集的所有标签值?
【发布时间】:2020-12-28 04:42:12
【问题描述】:

我有一个包含 4 个特征和 2 个标签(1 和 0)的数据集。 有没有办法可以检查该数据集的所有 1400 个标签值并返回它属于哪一行? 第 0-3 列是特征,第 4 列是标签值。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split

data = pd.read_csv('data_banknote_authentication.txt', header=None)

print(data.head())
print(data.tail())
print(data.info)
X = data.loc[:, :3]
Y = data[4]

【问题讨论】:

  • data[data[4]==0]?

标签: python pandas numpy dataframe machine-learning


【解决方案1】:

您可以通过以下方式查看所有 0 行:

data[data['4'] == 0]

和1s:

data[data['4'] == 1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-09
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2020-02-10
    • 2011-04-01
    相关资源
    最近更新 更多