pandas导出小绿标
时间: 2024-01-07 19:23:41 浏览: 83
以下是使用pandas导出小绿标的示例:
```python
import pandas as pd
# 创建DataFrame
lst = [
{"name": "Tom", "age": 23, "sex": 1},
{"name": "Jack", "age": 24, "sex": 0},
{"name": "Steve", "age": 25, "sex": 1},
]
df = pd.DataFrame(lst)
# 导出DataFrame到CSV文件
df.to_csv('./student.csv', columns=['name', 'age', 'sex'], header=['姓名', '年龄', '性别'], index_label='序号')
```
在上述示例中,我们首先导入pandas库。然后,我们创建了一个包含学生信息的DataFrame。接下来,我们使用`to_csv`方法将DataFrame导出到CSV文件。在`to_csv`方法中,我们使用`columns`参数指定要导出的列,使用`header`参数指定导出的列标题,使用`index_label`参数指定序号列的标题。最后,我们将导出的CSV文件保存为`student.csv`。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)