Tag: python

Out of Range error for sys.argv with Workbook.caller()

This issue is specific to xlwings. I’m having issues with wb = Workbook.caller(). Which results in the following error: Traceback (most recent call last): File “<string>”, line 1, in <module> File “WeatherDataAPI.py”, line 89, in <module> wb = Workbook.caller() File “C:\Python27\lib\site-packages\xlwings\main.py”, line 234, in caller xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=sys.argv[4]) IndexError: list index out of […]

Reading excel column 1 into Python dictionary key, column 2 into value

I have an excel sheet containing the following: Column1 Column2 A 1 B 2 C 3 D 4 I would like to read the sheet into a Python dictionary with: Key : Value A : 1 B : 2 C : 3 D : 4 How can I do this?

Does pandas read_excel actually open excel?

This is just a question out of interest more than anything else. I come from a MATLAB background whereby to read in Excel files the function in MATLAB actually goes about opening Excel to read in the data. Obviously this takes alot of time and so it can be slow but the read_excel function with […]

Leave dates as strings using read_excel function from pandas in python

Python 2.7.10 Tried pandas 0.17.1 — function read_excel Tried pyexcel 0.1.7 + pyexcel-xlsx 0.0.7 — function get_records() When using pandas in Python is it possible to read excel files (formats: xls|xlsx) and leave columns containing date or date + time values as strings rather than auto-converting to datetime.datetime or timestamp types? If this is not […]

Python append value to list of unique objects

Please forgive any naiveté in this question. I have been actively trying to form a rudimentary understanding of programming over the last few months. There are many gaps, so I may not know what I don’t know. The dataset I am working with is currently in excel, so VBA might be a good option, however […]

Converting CSV to XLSX using openpyxl, but quote comes infront of numbers

I tried to convert CSV to xlsx using openpyxl. The conversion was successful but i noticed quote (‘) in-front of numbers. Making it string instead of numbers. As I am new to python you help would be grateful. Here is code I am using: import os import glob import csv import openpyxl for csvfile in […]

How to search an xlsx file for a specific string using Python (and perhaps openpyxl)

How can I search an xlsx file for a specific string variable? Example: ORIGINAL TEXT FILE: one – a b c two – a b c three – a b c four – a b c five – a b c XLSX FILE: two three five OUTPUT CSV FILE: The following in two columns: two […]

Writing to Excel based on row values

I have an Excel file that looks like this (Col4 values are not letters, but names): col1 col2 col3 col4 —————————– row1 | 2,3,1 _ 1 w row2 | 3,2,7 _ 2 x row3 | _ _ 3 y row4 | 4,9 _ 4 z I want to write some values in column 2 that […]

Dealing with Nested Loops in Python – Options?

I have a function that looks like this (below). I’m using xlrd in python. Whenever I perform the “print path” function, I receive way too many iterations of path. Essentially, what I’m trying to do is compare two columns in excel, and print out a third. That works perfectly, except that the third is printed […]

Copied Excel Files losing Web query

I’m using Python and the module openpyxl. I have been able to: CreateFile = openpyxl.load_workbook(filename= ‘OldWorkbook.xlsm’, keep_vba = True) Sheet = CreateFile.active Sheet[‘A1’]=(“What Ever You Want”) CreateFile.save(‘NewWorkbook.xlsm’) But when I open the NewWorkbook the web query I defined in OldWorkbook is not there in NewWorkbook, any suggestions?

MS Excel Spreadsheet is the best Office Software, Excel VBA and Excel Formulas make Spreadsheet work faster.