用Python同时提取Excel中的申请号和申请日放在一起
时间: 2024-09-26 10:16:02 浏览: 34
在Python中,你可以使用pandas库来读取Excel文件并提取特定列的数据。首先,你需要安装`pandas`和`openpyxl`或`xlrd`(取决于你的Excel文件格式,xlsx通常使用`openpyxl`,xls则用`xlrd`)。下面是一个简单的例子,假设你的Excel文件有两列名为"申请号"和"申请日":
```python
import pandas as pd
# 读取Excel文件
def extract_data(file_path):
# 使用openpyxl读取xlsx文件,如果文件是.xls格式,可以替换为 xlrd.open_workbook
df = pd.read_excel(file_path)
# 提取申请号和申请日列
application_numbers = df['申请号'].tolist() # 或者直接 df['申请号']
application_dates = df['申请日'].tolist() # 或者直接 df['申请日']
# 结果作为一个字典返回,方便后续处理
result = {'申请号': application_numbers, '申请日': application_dates}
return result
file_path = 'your_file.xlsx' # 替换为你需要处理的Excel文件路径
data = extract_data(file_path)
```
在这个例子中,`df['申请号']` 和 `df['申请日']` 就分别获取了两个列的内容,然后转换成列表返回。
阅读全文
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)