pd.read_excel中读取数据显示non-null
时间: 2024-06-16 10:03:12 浏览: 19
在使用`pd.read_excel`函数读取Excel文件时,可以通过`df.info()`方法来查看数据的非空(non-null)值的情况。`df.info()`会显示DataFrame对象的基本信息,包括每列的名称、非空值的数量以及数据类型等。
以下是一个示例代码:
```python
import pandas as pd
# 读取Excel文件
df = pd.read_excel('data.xlsx')
# 查看数据的非空值情况
df.info()
```
执行以上代码后,会输出类似以下的信息:
```
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Name 1000 non-null object
1 Age 1000 non-null int64
2 Gender 998 non-null object
3 Address 997 non-null object
4 Score 1000 non-null float64
dtypes: float64(1), int64(1), object(3)
memory usage: 39.2+ KB
```
在上述输出中,`Non-Null Count`列显示了每列的非空值数量。例如,`Gender`列有998个非空值,`Address`列有997个非空值。