简体   繁体   English

有什么方法可以找到给定数据集中的缺失值

[英]Is there any way to find the missing values in given dataset

the code is as follows代码如下

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Dataset = pd.read_csv('/Users\HANISH\Desktop\mllearning\Datapreprocessing\Data.csv')
X = Dataset.iloc[:,:-1]
Y = Dataset.iloc[:,-1]

from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer.fit(X[:,1:3])
X[:,1:3] = imputer.transform(X[:,1:3])

print(X)

Data I am using is:我使用的数据是:

Dataset数据集

The error I am getting is as follows:我收到的错误如下:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File ~\.spyder-py3\temp1.py:18 in <module>
    imputer.fit(X[:,1:3])

  File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py:3505 in __getitem__
    indexer = self.columns.get_loc(key)

  File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py:3628 in get_loc
    self._check_indexing_error(key)

  File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py:5637 in _check_indexing_error
    raise InvalidIndexError(key)

InvalidIndexError: (slice(None, None, None), slice(1, 3, None))

Please suggest me the changes as I started just learning.请在我刚开始学习时建议我进行更改。

You need change X[:,1:3] to X.iloc[:,1:3]您需要将X[:,1:3]更改为X.iloc[:,1:3]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找出给定数据集中每列缺失值的百分比 - Find out the percentage of missing values in each column in the given dataset 有没有办法在给定的逻辑上拆分Spark数据集 - is there any way to split Spark Dataset in given logic 有什么简单的方法可以将概率质量 function 拟合到给定的数据集? - Is there any easy way to fit probability mass function to a given dataset? 如何在巨大数据集中的熊猫数据框中查找和转换缺失值? - how to find and convert missing values in a pandas dataframe in a HUGE dataset? 根据其他数据集中的列表查找缺失值的列名 - Find column names of missing values based on list from other dataset 在python中处理数据集中的缺失值 - Dealing with missing values in dataset in python 寻找数据集中缺失值的解决方案 - Seeking solution to Missing values in dataset 处理预测数据集中的缺失值 - Dealing with missing values in the prediction dataset 有没有办法手动修改从给定数据集学习到的决策树中设置的阈值? - Is there any way to manually modify the thresholds set in the decision tree learnt from a given dataset? pythonic在给定字符串中查找dataframe的列值的方法 - pythonic way to find column values of a dataframe in a given string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM