使用python查找Excel中的列中是否存在值 [英] Find if a value exists in a column in Excel using python

查看:2938
本文介绍了使用python查找Excel中的列中是否存在值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel文件,其中包含一个具有沉积物收集数据的工作表。我正在运行一个很长的Python脚本。



在工作表中有一个名为CollectionYear的列。说我想要2010年。如果2010年存在于CollectionYear列中,我想要剩下的脚本运行,如果没有,我想要脚本停止。



这似乎是一个容易的任务,但对于我的生活我无法弄清楚,也找不到任何例子。



任何帮助将不胜感激。

解决方案

尝试使用<一个href =http://xlwings.org/quickstart/ =nofollow> xlwings 与python接口的库



他们的文档示例:

 从xlwings导入工作簿,工作表,范围,图表
wb = Workbook()#创建与新工作簿的连接
Range('A1')。value ='Foo 1'
Range('A1')。value
>>> 'Foo 1'
Range('A1')。value = [['Foo 1','Foo 2','Foo 3'],[10.0,20.0,30.0]]


I have an Excel file with one worksheet that has sediment collection data. I am running a long Python script.

In the worksheet is a column titled "CollectionYear." Say I want the year 2010. If the year 2010 exists in the "CollectionYear" column, I want the rest of the script to run, if not then I want the script to stop.

This seems like an easy enough task but for the life of me I cannot figure it out nor find any examples.

Any help would be greatly appreciated.

解决方案

Try using xlwings library to interface with Excel from python

example from their docs:

from xlwings import Workbook, Sheet, Range, Chart
wb = Workbook()  # Creates a connection with a new workbook
Range('A1').value = 'Foo 1'
Range('A1').value
>>> 'Foo 1'
Range('A1').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]

这篇关于使用python查找Excel中的列中是否存在值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆