Struggling to get xlxswriter to create multiple worksheets and use the pandas df.to_excel method to place the data in there.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import xlsxwriter
import os as os
import sqlite3 as sql
import xlrd
path = (r'C:\Users\test1\Downloads\category.xlsx') #folder
data = pd.DataFrame()
data = pd.read_excel(path,sheetname='1')
print (data.shape)
data.head()
#create excel workbook using xlsxwriter
#workbook = xlsxwriter.Workbook('hyperlink.xlsx')
writer = ExcelWriter('hyperlink.xlsx')
data.to_excel(writer,'Sheet1')
workbook.close()
Related
I am getting that error and have already checked the forums & have found no answer as I do have the correct imports installed. Here is my current import list:
import xlwings as xw
import xlsxwriter as xlsx
import xlrd
import xlwt
from xlutils.copy import copy
import pandas as pd
import win32com.client as win32
import openpyxl as xl
from openpyxl import load_workbook
import numpy as np
import datetime
import os.path
import warnings
Here's the code I'm getting errors on:
wb = xlsx.Workbook(File_path)
ws = ws
ws.set_column('A:A', 60)
ws comes form:
ws = wb.get_worksheet_by_name('Data')
Any help would be greatly appreciated. Thanks!
You need to replace
ws = wb.sheets['Data']
with
ws = wb.get_worksheet_by_name('Data')
I wrote this small code. How can I remove the "hours" timing in the excel ? See the screenshot below.
import os
import yfinance
import pandas as pd
from openpyxl import Workbook
from openpyxl import load_workbook
a=yfinance.download('CS.PA', interval='1mo')
print(a)
save_name="C:\\Users\\Lex02\\Desktop\\Python2\\Bourse essai_3.xlsx"
a.to_excel(save_name)
a_excel=load_workbook(filename=save_name)
ws=a_excel.active
os.system('pause')
Thank you !
Format your index:
a = yfinance.download('CS.PA', interval='1mo')
a.index = a.index.strftime('%Y-%m-%d') # Enter whatever format here
I am trying to read an already existing excel file, and append some data in another sheet in that excel file. however, after closing the file, when i try to manually open it and do some manual calculation etc.. it's says that excel is read-only. can you please help me.
import numpy as np
import pandas as pd
import os, glob
import datetime as dt
import yfinance as yf
from openpyxl import load_workbook
ticker = "SBIN.NS"
start = dt.datetime.today() - dt.timedelta(5000)
end = dt.datetime.today()
ohlcv_data = pd.DataFrame()
temp_ticker = yf.Ticker(ticker)
ohlcv_data = temp_ticker.history(start=start,end=end,interval='1d')
writer = pd.ExcelWriter('D:/NSE/SBI.xlsx',engine='openpyxl',mode='a')
ohlcv_data.to_excel(writer, sheet_name='yahoo_data2')
writer.close()
Language: Python 3.8.3
I faced this error when I was importing my xlxs file ModuleNotFoundError: No module named 'xlxswriter'
import xlxswriter
import pandas as pd
from pandas import DataFrame
path = ('mypath.xlxs')
xl = pd.ExcelFile(path)
print(xl.sheet_names)
How can I fix this?
Instead of typing xlsx, type xlsx like this:
import xlsxwriter
import pandas as pd
from pandas import DataFrame
path = ('mypath.xlsx')
xl = pd.ExcelFile(path)
print(xl.sheet_names)
It'll work.
The module name is xlsxwriter not xlxswriter, so replace that line with:
import xlsxwriter
I'm new to python and I got this error I couldn't solve
import pandas as pd
import numpy as np
url = 'http://localhost:8888/edit/Downloads/untitled.cvs'
food2014_recalls = pd.read_csv(url)
This is my csv file:
animal,uniq_id,water_need
elephant,1001,500
elephant,1002,600
elephant,1003,550
I got this error:
import pandas as pd
import numpy as np
import io
import requests
url ='http://localhost:8888/edit/Downloads/untitled.cvs'
res =requests.get(url).content
food2014_recalls =pd.read_csv(io.StringIO(res.decode('utf-8')), error_bad_lines=False, comment='#', sep=',')