使用Pandas库读取StudentsInfo.csv文件,在控制台打印数据的基本信息,包括每列数据的类型和非空数量等
时间: 2024-02-18 09:58:56 浏览: 80
好的,我知道了。下面是使用Pandas库读取StudentsInfo.csv文件,在控制台打印数据的基本信息的代码:
```python
import pandas as pd
# 读取csv文件
df = pd.read_csv('StudentsInfo.csv')
# 打印数据的基本信息
print('数据的形状为:', df.shape)
print('数据的大小为:', df.size)
print('数据的列名为:', df.columns.tolist())
print('数据的索引名为:', df.index.tolist())
print('数据的每一列的数据类型为:\n', df.dtypes)
print('数据每一列的非空数量为:\n', df.count())
```
以上代码中,我们首先使用Pandas库的read_csv()函数读取了StudentsInfo.csv文件,并将数据存储在DataFrame类型的变量df中。然后,我们分别使用shape、size、columns、index、dtypes和count等属性和方法打印了数据的基本信息,包括数据的形状、大小、列名、索引名、每一列的数据类型和每一列的非空数量等。
相关问题
从studentsInfo.xlsx 文件的"Group1"表单中读取数据(可指定 sheet_name='Group1'的参数), 将第0列设为索引列, 得到数据框对象 df
好的,你可以使用 pandas 库中的 `read_excel` 函数来读取 `studentsInfo.xlsx` 文件的 "Group1" 表单,并将第0列设为索引列,得到数据框对象 df,代码如下所示:
```python
import pandas as pd
df = pd.read_excel('studentsInfo.xlsx', sheet_name='Group1', index_col=0)
```
其中,`index_col=0` 表示将第0列作为索引列。请确保当前工作目录下存在 `studentsInfo.xlsx` 文件,并且 "Group1" 表单存在。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)