Python 3.6 Newest openpyxl
So, I'm working with an excel using openpyxl. I have a very boring test.xlsx excel, which I can read with the following code:
import os
import openpyxl
wb = openpyxl.load_workbook('test.xlsx')
sheet = wb['Sheet1']
print(sheet)
However, when I change to a fairly complex excel document 'apqptest.xlsx.'
import os
import openpyxl
wb = openpyxl.load_workbook('apqptest.xlsx')
sheet = wb['Sheet1']
print(sheet)
I get the following error (I have created the same sheet1 on the apqptest.xlsx document just fyi):
C:\Users\nkent\PycharmProjects\webscraper\venv\Scripts\python.exe "C:/Users/nkent/Desktop/Programs/Quote Preperation.py"
Traceback (most recent call last):
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\base.py", line 57, in _convert
value = expected_type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/nkent/Desktop/Programs/Quote Preperation.py", line 3, in <module>
wb = openpyxl.load_workbook('apqptest.xlsx')
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\reader\excel.py", line 274, in load_workbook
for c in find_charts(archive, rel.target):
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\chart\reader.py", line 43, in find_charts
drawing = SpreadsheetDrawing.from_tree(tree)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
obj = desc.expected_type.from_tree(el)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
obj = desc.expected_type.from_tree(el)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
obj = desc.expected_type.from_tree(el)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 100, in from_tree
return cls(**attrib)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\drawing\graphic.py", line 53, in __init__
self.rot = rot
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\base.py", line 69, in __set__
value = _convert(self.expected_type, value)
File "C:\Users\nkent\PycharmProjects\webscraper\venv\lib\site-packages\openpyxl\descriptors\base.py", line 59, in _convert
raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'int'>
Related
import csv
import requests
from bs4 import BeautifulSoup
import wget
with open('__memes_magic_thumbnails.csv', newline='') as csvfile:
data = list(csv.reader(csvfile))
print(data)
k=0
for link in data:
print(k)
wget.download(link , "vid/logo.jpg")
k+=1
print("succes")
for this code im getting the following error
Traceback (most recent call last):
File "i:\Meme Channel\channel1\automated_youtube_channel-master\automated_youtube_channel-master\scraper.py", line 12, in <module>
wget.download(link , "vid/logo.jpg")
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\site-packages\wget.py", line 505, in download
prefix = detect_filename(url, out)
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\site-packages\wget.py", line 484, in detect_filename
names["url"] = filename_from_url(url) or ''
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\site-packages\wget.py", line 230, in filename_from_url
fname = os.path.basename(urlparse.urlparse(url).path)
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 392, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 128, in _coerce_args return _decode_args(args) + (_encode_result,)
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 112, in _decode_args return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "C:\Users\Sambhaji Karbhari\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 112, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'list' object has no attribute 'decode'
here i downloading a image from the link which is taken fro array which is inserted in it from a csv file.
I'm new to openpyxl. I need to copy several columns from a file and paste it on another file, with the same columns.
I'm starting my code, but getting an error:
file1 = load_workbook('PRODUCTION.xlsx') ws = file1.active column = ws.cell['ID'] print (column)
I get this error:
Traceback (most recent call last): File "c:\Users\Ana\Documents\PRODUCTION Project\production.py", line 29, in <module> column = ws.cell['ID'] TypeError: 'method' object is not subscriptable
And when I tried only column = ws ['ID']
I get:
Traceback (most recent call last): File "c:\Users\Ana\Documents\PRODUCTION Project\production.py", line 29, in <module> column = ws ['ID'] File "C:\Users\Ana\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\worksheet\worksheet.py", line 290, in __getitem__ min_col, min_row, max_col, max_row = range_boundaries(key) File "C:\Users\Ana\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\utils\cell.py", line 135, in range_boundaries raise ValueError(msg) ValueError: ID is not a valid coordinate or range PS C:\Users\Ana\Documents\PRODUCTION Project>
Thanks in advance.
I am getting error message when im trying to write to my excel file.
On this line: df_Percent_Change.to_excel(writer, sheet_name=x, startcol=8)
Traceback (most recent call last):
File "/Users/david.soderstrom/Dropbox (Diagona)/DS/Python/Byggmarknad_index/Byggmarknad_index.py", line 125, in
df_Percent_Change.to_excel(writer, sheet_name=x, startcol=8)
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py", line 1766, in to_excel
engine=engine)
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/pandas/io/formats/excel.py", line 652, in write
freeze_panes=freeze_panes)
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/pandas/io/excel.py", line 1742, in write_cells
wks = self.book.add_worksheet(sheet_name)
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/xlsxwriter/workbook.py", line 179, in add_worksheet
return self._add_sheet(name, worksheet_class=worksheet_class)
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/xlsxwriter/workbook.py", line 666, in _add_sheet
name = self._check_sheetname(name, isinstance(worksheet, Chartsheet))
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/xlsxwriter/workbook.py", line 717, in _check_sheetname
if len(sheetname) > 31:
TypeError: object of type 'int' has no len()
Exception ignored in: >
Traceback (most recent call last):
File "/Users/david.soderstrom/anaconda3/lib/python3.6/site-packages/xlsxwriter/workbook.py", line 154, in del
Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook.
# Calculate and save the percent change for each asset
if 'Percent_Change' not in excel_db.columns:
print('Percent_Change does not exist in excel file.')
print('Calculating...')
# Loop through and read each sheet
x = 0
for x in range(countSheets):
# Read in data for the calculation
data = pd.read_excel('databas.xlsx', sheet_name=x, index_col='Date')
# Calculate the percent change from day to day
Percent_Change = data['Adj Close'].pct_change()*100
print(type(Percent_Change))
df_Percent_Change = pd.DataFrame(Percent_Change)
print(type(df_Percent_Change))
writer = pd.ExcelWriter('databas.xlsx', engine='xlsxwriter')
df_Percent_Change.to_excel(writer, sheet_name=x, startcol=8)
# Save the result
writer.save()
writer.close()
x += 1
I'm simply trying to upload excel.xlsx file with Python panda package so i can tokenize the text. I tried for hours but nothing works. Any help will be great:
import pandas as pd
excel_file = open(r'''C:\Users\farid-PC\Desktop\Tester.xlsx''', errors
='ignore')
movies = pd.read_excel(excel_file)
movies.head()
Errors:
Traceback (most recent call last):
File "C:/Users/farid-PC/PycharmProjects/fake_news/fault.py", line 4, in <module>
movies = pd.read_excel(excel_file)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\pandas\util\_decorators.py", line 178, in wrapper
return func(*args, **kwargs)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\pandas\util\_decorators.py", line 178, in wrapper
return func(*args, **kwargs)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\pandas\io\excel.py", line 307, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\pandas\io\excel.py", line 392, in __init__
self.book = xlrd.open_workbook(file_contents=data)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\xlrd\__init__.py", line 162, in open_workbook
ragged_rows=ragged_rows,
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\xlrd\book.py", line 91, in open_workbook_xls
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\xlrd\book.py", line 1267, in getbof
opcode = self.get2bytes()
File "C:\Users\farid-PC\PycharmProjects\fake_news\venv\lib\site-packages\xlrd\book.py", line 672, in get2bytes
return (BYTES_ORD(hi) << 8) | BYTES_ORD(lo)
TypeError: unsupported operand type(s) for <<: 'str' and 'int'
I tried the following code:
import pandas_datareader.data as web import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2017, 10, 26)
f = web.DataReader("F", 'yahoo', start, end)
and got the following error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
f.Close
File "C:\Python34\lib\idlelib\rpc.py", line 611, in displayhook
text = repr(value)
File "C:\Python34\lib\site-packages\pandas\core\base.py", line 72, in __repr__
return str(self)
File "C:\Python34\lib\site-packages\pandas\core\base.py", line 51, in __str__
return self.__unicode__()
File "C:\Python34\lib\site-packages\pandas\core\series.py", line 982, in __unicode__
width, height = get_terminal_size()
File "C:\Python34\lib\site-packages\pandas\io\formats\terminal.py", line 33, in get_terminal_size
return shutil.get_terminal_size()
File "C:\Python34\lib\shutil.py", line 1071, in get_terminal_size
size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
I use Python 3.4 [wrong: 3.5] with pandas 0.2 when the error occured. The same code on Python 3.6 with pandas 0.2 runs without problems on another work station. Anybody any idea how I can fix the error.
I allready tried to uninstall and to reinstall pandas and pandas-datareader but it didn't helped.