从特定列中查找缺失数据的行

问题描述 投票:0回答:1

如何在 Jupyter 中查找特定列中缺失数据的行数?数据集有大量行。

例如第1034行和第2045行有缺失数据,需要执行什么代码才能找到这些行?

代码适用于 Jupyter Notebook 或 Python 代码。

谢谢您的帮助!

python jupyter-notebook dataset jupyter
1个回答
0
投票

根据我对您问题的理解,我认为以下代码示例可以帮助您:

import pandas as pd

# Read the dataset into a pandas DataFrame
df = pd.read_csv('your_dataset.csv')

# Specify the column name where you want to find missing data
column_name = 'your_column_name'

# Specify the range of rows to search within
start_row = 1034
end_row = 2045

# Find the row indices with missing data in the specified column within the range
missing_indices = df.loc[start_row:end_row, column_name[df.loc[start_row:end_row, column_name].isnull()].index.tolist()

# Print the row indices
print(missing_indices)
© www.soinside.com 2019 - 2024. All rights reserved.