Tag: python

我可以确保单元格是使用Pandas Xlsxwriter写入date或时间格式吗?

我正在使用Pandas Xlsxwriter将文件创build时间写入Excel表格,但是我无法find我可以指定单元格格式的位置。 因此,我的时间戳以Excel中的文本forms出现 这是我的代码的相关部分 for d, dirs, files in os.walk(folder): for f in files: full_name = path.join(d, f) if path.isfile(full_name): time_info = [(fn(full_name)) for fn in (path.getatime, path.getmtime, path.getctime)] dict1 = [datetime.fromtimestamp(time_info[0]).strftime('%d.%m.%Y %H:%M:%S'), datetime.fromtimestamp(time_info[0]).strftime('%d.%m.%Y %H:%M:%S')] dict2.append(dict1) df = pd.DataFrame(dict2, columns=('the last access time', 'time changes') writer = pd.ExcelWriter('listdir1.xlsx', engine='xlsxwriter', datetime_format='dd.mm.yyyy', date_format='dd.mm.yyyy') df.to_excel(writer, index=False) writer.save() 这是它在Excel中的外观

tomcat / CGI和python3无法使用win32com打开Excel文件

我有一个PY3脚本,它使用Win32COM来实例化一个新的Excel实例,并试图打开一个现有的.xlsx文件 – 在Windows上通过Tomcat / CGI调用时失败: sys.stdout.write("Content-Type: text/html\n\n") excel = DispatchEx('Excel.Application') dir = r'C:\temp' s = 'test.xlsx' sfile = os.path.join(dir, s) try: wbS = excel.Workbooks.Open(sfile) except pythoncom.com_error as error: print("exception details: {0}".format(error)) exit(1) 操作失败: exception details: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Microsoft Excel cannot access the file 'C:\\temp\\test.xlsx'. There are several possible reasons:\n\n• The file […]

用多个数组parsingJSON并使用Python 3.6比较Excel数据

我有一个像这样的JSON: { "results": [{ "data": { "child": [{ "sex": "2", "birthDateReliability": "0", "applicationInternalIdentifier": "cmpclt", "birthDate": "2016-07-04", "firstName": "Anna" }], "consumerType": "PRIVATE", "countryCode": "FR", "initialAppSourceCode": "ABCDWEB", "optin": [{ "optinSourceApplication": "ABCDWEB", "acceptanceDate": "2017-02-10T10:14:55.037Z", "marketingGroupService": "XYZXYX-ABC" }, { "optinSourceApplication": "ABCDWEB", "acceptanceDate": "2017-02-10T10:14:55.037Z", "marketingGroupService": "XYZXYX-DEF" }, { "optinSourceApplication": "ABCDWEB", "acceptanceDate": "2017-02-10T10:14:55.037Z", "marketingGroupService": "XYZXYX-GHI" }, { "optinSourceApplication": "ABCDWEB", "acceptanceDate": "2017-02-10T10:14:55.037Z", […]

用大pandas过滤excel数据时出现KeyError错误

我正在尝试从Python中的Excel数据中读取和过滤。 我使用下面的代码: import pandas as pd import numpy as np df = pd.read_excel('file.xlsx') df['apples'] = (pd.cut(df['apples'],bins=[-np.inf,2,5,np.inf],labels=['WOW','ok','BOB'])) print(df) 这是我的excel文件 但KeyError:“苹果”发生。 你有什么build议,我该如何解决这个问题?

在Visual Basic中使用Excel时出现xlwings和sqlalchemy问题

我已经下载并安装了所有需要的程序,假设已经安装了python + pandas。 在安装xlwings和sqlalchemy之后,根据我正在使用的教程,它说xlwings和Module1应该出现在Visual Basic中,但是这完全没有发生。 我在这里做错了什么? 在Excel中没有问题,但打开Visual Basic后,我看不到xlwings和Module1: 原来的教程得到了一切:

xlrd&openpyxl提取错误的单元格值(Excel)

需要帮助,请! 看起来像一个简单的任务 – 我需要从特定的电子表格单元格中提取值并总结出来。 但是,即使在第一步,我也失败了 – 取而代之。 起初,我认为模块是错误的(openpyxl正在定期升级,我错过了一些东西),但是xlrd模块产生了相同的错误结果! 代码如下: import xlrd, xlwt wb = xlrd.open_workbook(r"E:\Projects_working (11).xlsx") sheet = wb.sheet_by_name('Language Process') for i in range(1, 100): cellVal = sheet.cell(i, 14).value #need to find "5" in column 14 if type(cellVal) == float and cellVal == 5.0: #need to read corresp. print(sheet.cell(i, 11).value) #values в column 11 结果,而不是一个整数(比如22),代码结束了一个浮点数42782.61458。 […]

python脚本来刷新电子表格的BLOOMBERG数据

我有一大堆的excle表单,这些表单在bloomberg结束的时候用到了Python中的各种东西。 我的问题如下: 有没有办法告诉表来刷新彭博资料? 传统的刷新都不起作用,就像在Excel中打f9一样,不会刷新它们。 我知道如何做的唯一方法是在bloomberg标签下单击(在Excel中)刷新图标,两个箭头。 我很想自动化。 这是我现在所拥有的: import win32com.client import time def refr_sheet(): app_global = win32com.client.Dispatch("Excel.Application") global_sprdsheet = app_global.Workbooks.open('C:\\Users\\Ako\\Desktop\\ako_files\\work_sheets\\global.xlsx') global_sprdsheet.RefreshAll() time.sleep(12) global_sprdsheet.Save() global_sprdsheet.Close() app_global.Quit() 哪些工作重新计算一般Excel计算公式,但不会刷新bloomberg(= BHDtypes)公式。 欢迎任何build议!

比较python中不同长度的列

我有两个擅长文件(浓度,排放)。 两列都有:A =年份,B =月份,C =date,D =浓度/排放量。 但不同的长度。 对于排放,我有过去30年的日常数据(很多行),对于集中,我有几个月的数据。 我需要的是同一天的排放和集中的附加清单。 然后再绘制这个值。 但是,我把数据集中到excel的日子里,手动…真是太乏味了 – 我用python试过了,但是我不知道如何处理不同长度的…谢谢:=) import pandas as pd concentration= pd.read_excel() discharge= pd.read_excel() a = concentration.iloc[:,3:4] year_c= concentration.iloc[:,0] year_d= discharge.iloc[:,0] month_c=concentration.iloc[:,1] month_d=discharge.iloc[:,1] day_c= concentration.iloc[:,2] day_d= discharge.iloc[:,2] Q=[] for element in a: if year_c == year_d and month_c == month_d and day_c == day_d: Q.append(a)

取消隐藏和隐藏工作簿中的列

如果数据不是他们的数据,他们是否将数据隐藏在Excel工作簿中? 比如说我用 df = pd.read_excel('Test.xlsx) 它产生的数据框有一个表格,其中有1月至12月已经制作的列因为我只有1月份和2月份的数据,所以我只希望显示这些列。 原因是三月到十二月没有数据,所以栏目空白。 我想基本上隐藏列,除非他们是在他们的数据,当数据确实存在于这些列我希望它取消隐藏,并显示该月的数据。

用Excel数据填充PDF表单

我有一个Excel电子表格,例如: Patent No. Issue Date Patentee 7,777,776 2010-08-17 Horiuchi 7,777,778 2010-08-17 Scharenbroch, et al. 我想用这些数据填写下面的表格: https : //www.uspto.gov/sites/default/files/patents/process/file/efs/guidance/updated_IDS.pdf 请注意,PDF表单上有一个添加button,用于在电子表格的第二行中创buildPDF中的第二行。 我对Python很熟悉,但是我看到的类似的解决scheme要么从头开始创build新的表单( 我怎样才能自动填充Django / Python中的PDF表单 ),也不要操作PDF表单中的添加button( 批量填充PDFforms从python或bash )。