我需要编写一个python脚本来读取excel文件,找到每个工作表,然后使用excel中定义的标准格式将这些打印到pdf.
我发现了以下问题如何在Python中打开Excel文件?它指向我http://www.python-excel.org/
这使我能够找到每个工作表的名称.
import xlrd
book = xlrd.open_workbook("myfile.xls")
print "Worksheet name(s):", book.sheet_names()
Run Code Online (Sandbox Code Playgroud)
这导致了
Worksheet name(s): [u'Form 5', u'Form 3', u'988172 Adams Road', u'379562 Adams Road', u'32380 Adams Road', u'676422 Alderman Road', u'819631 Appleyard Road', u'280998 Appleyard Road', u'781656 Atkinson Road', u'949461 Barretts Lagoon Road', u'735284 Bilyana Road', u'674784 Bilyana Road', u'490894 Blackman Road', u'721026 Blackman Road']
Run Code Online (Sandbox Code Playgroud)
现在我想打印以数字开头的每个工作表到pdf.
所以我可以
worksheetList=book.sheet_names()
for worksheet in worksheetList:
if worksheet.find('Form')!=0: #this just leaves out worksheets with the word 'form' in it
<function …Run Code Online (Sandbox Code Playgroud) 我需要在os.walk进程中获取当前目录.它只在一个子目录级别有效,但在有更多时失败.请指教...
[码]
# AFFECTS everything reachable from the directory named in "top",
# assuming there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could affect all your disk files.
import os, glob, arcpy, csv, sys, shutil, datetime
top = r'L:\Raster_Data\Topographic_Maps'
RootOutput = r'L:\Raster_Data\Topographic_Maps'
#FileList = csv.reader(open('FileList.csv'))
SearchString=['Temp_Pol', 'Spatial_Ex']
filecount=0
successcount=0
errorcount=0
print "Working in: "+os.getcwd()
list =[]
f = open(RootOutput+'\\Success_LOG.txt', 'a')
f.write("Log of files Succesfully processed. RESULT of process run @:"+str(datetime.datetime.now())+"\n") …Run Code Online (Sandbox Code Playgroud) ---更新3:我有脚本将所需数据更新为已完成的xml文件,但是从写入的文件中删除了以下代码.为什么是这样?我怎么能取代它?
<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='ANZMeta.xsl'?>
Run Code Online (Sandbox Code Playgroud)
当前工作代码(上述问题除外).
import os, xml, arcpy, shutil
from xml.etree import ElementTree as et
path=os.getcwd()
arcpy.env.workspace = path
FileList = arcpy.ListFeatureClasses()
FileCount = len(FileList)
zone="_Zone"
for File in FileList:
FileDesc_obj = arcpy.Describe(File)
FileNm=FileDesc_obj.file
newMetaFile=FileNm+"_BaseMetadata.xml"
check_meta=os.listdir(path)
if FileNm+'.xml' in check_meta:
shutil.copy2(FileNm+'.xml', newMetaFile)
else:
shutil.copy2('L:\Data_Admin\QA\Metadata_python_toolset\Master_Metadata.xml', newMetaFile)
tree=et.parse(newMetaFile)
print "Processing: "+str(File)
for node in tree.findall('.//title'):
node.text = str(FileNm)
for node in tree.findall('.//northbc'):
node.text = str(FileDesc_obj.extent.YMax)
for node in tree.findall('.//southbc'):
node.text = str(FileDesc_obj.extent.YMin)
for node in tree.findall('.//westbc'):
node.text = str(FileDesc_obj.extent.XMin) …Run Code Online (Sandbox Code Playgroud) 我有几个大文本文本文件都具有相同的结构,我想删除前3行,然后从第4行删除非法字符.我不想读取整个数据集然后修改,因为每个文件超过100MB,超过400万条记录.
Range 150.0dB -64.9dBm
Mobile unit 1 Base -17.19968 145.40369 999.8
Fixed unit 2 Mobile -17.20180 145.29514 533.0
Latitude Longitude Rx(dB) Best unit
-17.06694 145.23158 -050.5 2
-17.06695 145.23297 -044.1 2
Run Code Online (Sandbox Code Playgroud)
因此应该删除第1,2和3行,在第4行中,"Rx(db)"应该只是"Rx","Best Unit"应该更改为"Best_Unit".然后我可以使用我的其他脚本对数据进行地理编码.
我不能使用像grep这样的命令行程序(如本问题所示)因为前3行并不完全相同 - 每个文件中的数字(例如150.0dB,-64*)都会改变,所以你必须删除整行1-3然后grep或类似可以在第4行进行搜索替换.
多谢你们,
===编辑新的pythonic方式来处理来自@heltonbiker的更大文件.错误.
import os, re
##infile = arcpy.GetParameter(0)
##chunk_size = arcpy.GetParameter(1) # number of records in each dataset
infile='trc_emerald.txt'
fc= open(infile)
Name = infile[:infile.rfind('.')]
outfile = Name+'_db.txt'
line4 = fc.readlines(100)[3]
line4 = re.sub('\([^\)].*?\)', '', line4)
line4 = re.sub('Best(\s.*?)', 'Best_', line4)
newfilestring = …Run Code Online (Sandbox Code Playgroud) 当我比较正确上传(到 Mapillary 中)的文件和 EXIFTOOLS 中失败的 jpg 文件时,我发现它没有创建日期、原始日期/时间和修改日期。还有很多其他领域,但这些是唯一涉及时间的领域。
当我尝试使用时
'.\exiftool(-k).exe' -"Date/Time Original"="2019:10:27 18:14:10.5" Photo_2019_Jul_12_13_38_40_019.jpg
Run Code Online (Sandbox Code Playgroud)
它不允许我添加标签(我假设),因为它里面有一个“/”。例如,它也不允许“创建日期”。

我如何用这些创建标签?
一些示例文件位于https://drive.google.com/drive/folders/1QCQdSvdk0RygfCqqRWaOj-IzBbj17gax?usp=sharing
我有一个数据集,其中一列的标题是"你的位置和时区是什么?"
这意味着我们有像这样的条目
乃至
有没有办法从中提取城市,国家和时区?
我想所有的国家名称(包括缩写形式)以及城市名称/时区和创建数组(从一个开源的数据集)的,然后如果在数据集中的任何字与一个城市/国家/时区匹配或简短表单将它填入同一数据集中的新列并对其进行计数.
这有用吗?
===========基于NLTK答案的REPLT ============
运行与Alecxe相同的代码
Traceback (most recent call last):
File "E:\SBTF\ntlk_test.py", line 19, in <module>
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
File "C:\Python27\ArcGIS10.4\lib\site-packages\nltk\tag\__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "C:\Python27\ArcGIS10.4\lib\site-packages\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Python27\ArcGIS10.4\lib\site-packages\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Python27\ArcGIS10.4\lib\site-packages\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Python27\ArcGIS10.4\lib\site-packages\nltk\data.py", line 924, in …Run Code Online (Sandbox Code Playgroud)