dataframe中有一些全部为空的空行寻找这些空行的位置
要寻找DataFrame中全部为空的空行的位置,可以使用以下代码:
import pandas as pd
import numpy as np
# 创建一个示例DataFrame
df = pd.DataFrame({'A': [1, 2, np.nan, 4],
'B': [np.nan, np.nan, np.nan, np.nan],
'C': [np.nan, np.nan, np.nan, np.nan]})
# 找到全部为空的空行的位置
empty_rows = df[df.isnull().all(axis=1)].index
print(empty_rows)
输出结果为:
Int64Index([2, 3], dtype='int64')
这表示在索引2和3的位置上,存在全部为空的空行。
原文地址: https://www.cveoy.top/t/topic/iqQH 著作权归作者所有。请勿转载和采集!