I have created a webscraper that pulls data from thru chrome driver, puts it into a dataframe, and prints all the values. In order to do some trend analysis, I plan to run the code 5 times a day each day. Therefore I want to put the data into excel by creating a new sheet during each cycle.
My data is in a dataframe format. My issue stems from:
Using openpyxl - cannot input the df format referenced in the code below
Using pandas - the data has been getting overwritten in sheet 1. I want each sheet to have a timestamp of when it ran, but this completely overwrites.
So the way I see it, I can either get pandas to add a new workbook during each run cycle (ie adding a new sheet and appending the data there) or I need to figure out a way to get the df into openpyxl format.
from datetime import datetime
import pandas as pd
import numpy as np
path = r"C:\\Users\\Jacob\\Documents\\MyStuff\\weather.xlsx"
now = datetime.now()
j = now.strftime("%m-%d, %H.%M.%S")
x1 = all_weather
df1 = pd.DataFrame(x1)
writer = pd.ExcelWriter(path, engine = 'xlsxwriter')
df1.to_excel(writer, sheet_name = str(j))
writer.save()
writer.close()
OR
book = load_workbook('C:\\Users\\Jacob\\Documents\\MyStuff\\weather.xlsx')
now = datetime.now()
j = now.strftime("%m-%d, %H.%M.%S")
sheet = book.create_sheet(str(j))
sheet.append(weather_df)
When using openpyxl
TypeError: Value must be a list, tuple, range or generator, or a dict. Supplied value is
When using pandas sheet gets overwritten each time.